@wordpress/edit-site 4.19.0 → 5.0.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 (319) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/components/add-new-template/add-custom-template-modal.js +1 -0
  3. package/build/components/add-new-template/add-custom-template-modal.js.map +1 -1
  4. package/build/components/add-new-template/index.js +8 -5
  5. package/build/components/add-new-template/index.js.map +1 -1
  6. package/build/components/add-new-template/new-template-part.js +21 -6
  7. package/build/components/add-new-template/new-template-part.js.map +1 -1
  8. package/build/components/add-new-template/new-template.js +12 -8
  9. package/build/components/add-new-template/new-template.js.map +1 -1
  10. package/build/components/app/index.js +15 -30
  11. package/build/components/app/index.js.map +1 -1
  12. package/build/components/block-editor/editor-canvas.js +64 -0
  13. package/build/components/block-editor/editor-canvas.js.map +1 -0
  14. package/build/components/block-editor/index.js +61 -59
  15. package/build/components/block-editor/index.js.map +1 -1
  16. package/build/components/block-editor/resizable-editor.js +10 -44
  17. package/build/components/block-editor/resizable-editor.js.map +1 -1
  18. package/build/components/editor/index.js +80 -127
  19. package/build/components/editor/index.js.map +1 -1
  20. package/build/components/global-styles/block-preview-panel.js +42 -0
  21. package/build/components/global-styles/block-preview-panel.js.map +1 -0
  22. package/build/components/global-styles/context-menu.js +6 -2
  23. package/build/components/global-styles/context-menu.js.map +1 -1
  24. package/build/components/global-styles/custom-css.js +61 -0
  25. package/build/components/global-styles/custom-css.js.map +1 -0
  26. package/build/components/global-styles/dimensions-panel.js +2 -6
  27. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  28. package/build/components/global-styles/global-styles-provider.js +15 -2
  29. package/build/components/global-styles/global-styles-provider.js.map +1 -1
  30. package/build/components/global-styles/hooks.js +5 -2
  31. package/build/components/global-styles/hooks.js.map +1 -1
  32. package/build/components/global-styles/palette.js +1 -1
  33. package/build/components/global-styles/palette.js.map +1 -1
  34. package/build/components/global-styles/screen-block-list.js +2 -1
  35. package/build/components/global-styles/screen-block-list.js.map +1 -1
  36. package/build/components/global-styles/screen-block.js +10 -2
  37. package/build/components/global-styles/screen-block.js.map +1 -1
  38. package/build/components/global-styles/screen-border.js +43 -0
  39. package/build/components/global-styles/screen-border.js.map +1 -0
  40. package/build/components/global-styles/screen-colors.js +1 -1
  41. package/build/components/global-styles/screen-colors.js.map +1 -1
  42. package/build/components/global-styles/screen-css.js +42 -0
  43. package/build/components/global-styles/screen-css.js.map +1 -0
  44. package/build/components/global-styles/screen-layout.js +0 -5
  45. package/build/components/global-styles/screen-layout.js.map +1 -1
  46. package/build/components/global-styles/screen-root.js +14 -1
  47. package/build/components/global-styles/screen-root.js.map +1 -1
  48. package/build/components/global-styles/screen-style-variations.js +3 -3
  49. package/build/components/global-styles/screen-style-variations.js.map +1 -1
  50. package/build/components/global-styles/ui.js +50 -4
  51. package/build/components/global-styles/ui.js.map +1 -1
  52. package/build/components/global-styles/use-global-styles-output.js +5 -1
  53. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  54. package/build/components/global-styles/utils.js +3 -3
  55. package/build/components/global-styles/utils.js.map +1 -1
  56. package/build/components/{editor/global-styles-renderer.js → global-styles-renderer/index.js} +4 -8
  57. package/build/components/global-styles-renderer/index.js.map +1 -0
  58. package/build/components/header-edit-mode/document-actions/index.js +12 -5
  59. package/build/components/header-edit-mode/document-actions/index.js.map +1 -1
  60. package/build/components/header-edit-mode/index.js +19 -12
  61. package/build/components/header-edit-mode/index.js.map +1 -1
  62. package/build/components/keyboard-shortcuts/index.js +11 -1
  63. package/build/components/keyboard-shortcuts/index.js.map +1 -1
  64. package/build/components/layout/index.js +231 -0
  65. package/build/components/layout/index.js.map +1 -0
  66. package/build/components/list/header.js +5 -1
  67. package/build/components/list/header.js.map +1 -1
  68. package/build/components/list/index.js +4 -22
  69. package/build/components/list/index.js.map +1 -1
  70. package/build/components/navigate-to-link/index.js +1 -3
  71. package/build/components/navigate-to-link/index.js.map +1 -1
  72. package/build/components/routes/index.js +1 -1
  73. package/build/components/routes/index.js.map +1 -1
  74. package/build/components/sidebar/index.js +42 -0
  75. package/build/components/sidebar/index.js.map +1 -0
  76. package/build/components/sidebar-edit-mode/global-styles-sidebar.js +24 -4
  77. package/build/components/sidebar-edit-mode/global-styles-sidebar.js.map +1 -1
  78. package/build/components/sidebar-edit-mode/index.js +1 -1
  79. package/build/components/sidebar-edit-mode/index.js.map +1 -1
  80. package/build/components/sidebar-navigation-item/index.js +53 -0
  81. package/build/components/sidebar-navigation-item/index.js.map +1 -0
  82. package/build/components/sidebar-navigation-screen/index.js +49 -0
  83. package/build/components/sidebar-navigation-screen/index.js.map +1 -0
  84. package/build/components/sidebar-navigation-screen-main/index.js +76 -0
  85. package/build/components/sidebar-navigation-screen-main/index.js.map +1 -0
  86. package/build/components/sidebar-navigation-screen-templates/index.js +188 -0
  87. package/build/components/sidebar-navigation-screen-templates/index.js.map +1 -0
  88. package/build/components/site-icon/index.js +70 -0
  89. package/build/components/site-icon/index.js.map +1 -0
  90. package/build/components/site-title/index.js +55 -0
  91. package/build/components/site-title/index.js.map +1 -0
  92. package/build/components/style-book/index.js +173 -0
  93. package/build/components/style-book/index.js.map +1 -0
  94. package/build/components/{url-query-controller/index.js → sync-state-with-url/use-init-edited-entity-from-url.js} +5 -4
  95. package/build/components/sync-state-with-url/use-init-edited-entity-from-url.js.map +1 -0
  96. package/build/components/sync-state-with-url/use-sync-sidebar-path-with-url.js +53 -0
  97. package/build/components/sync-state-with-url/use-sync-sidebar-path-with-url.js.map +1 -0
  98. package/build/index.js +2 -45
  99. package/build/index.js.map +1 -1
  100. package/build/store/actions.js +93 -43
  101. package/build/store/actions.js.map +1 -1
  102. package/build/store/reducer.js +35 -107
  103. package/build/store/reducer.js.map +1 -1
  104. package/build/store/selectors.js +69 -78
  105. package/build/store/selectors.js.map +1 -1
  106. package/build-module/components/add-new-template/add-custom-template-modal.js +1 -0
  107. package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -1
  108. package/build-module/components/add-new-template/index.js +7 -5
  109. package/build-module/components/add-new-template/index.js.map +1 -1
  110. package/build-module/components/add-new-template/new-template-part.js +18 -6
  111. package/build-module/components/add-new-template/new-template-part.js.map +1 -1
  112. package/build-module/components/add-new-template/new-template.js +13 -9
  113. package/build-module/components/add-new-template/new-template.js.map +1 -1
  114. package/build-module/components/app/index.js +15 -28
  115. package/build-module/components/app/index.js.map +1 -1
  116. package/build-module/components/block-editor/editor-canvas.js +51 -0
  117. package/build-module/components/block-editor/editor-canvas.js.map +1 -0
  118. package/build-module/components/block-editor/index.js +61 -60
  119. package/build-module/components/block-editor/index.js.map +1 -1
  120. package/build-module/components/block-editor/resizable-editor.js +11 -40
  121. package/build-module/components/block-editor/resizable-editor.js.map +1 -1
  122. package/build-module/components/editor/index.js +81 -124
  123. package/build-module/components/editor/index.js.map +1 -1
  124. package/build-module/components/global-styles/block-preview-panel.js +32 -0
  125. package/build-module/components/global-styles/block-preview-panel.js.map +1 -0
  126. package/build-module/components/global-styles/context-menu.js +7 -3
  127. package/build-module/components/global-styles/context-menu.js.map +1 -1
  128. package/build-module/components/global-styles/custom-css.js +51 -0
  129. package/build-module/components/global-styles/custom-css.js.map +1 -0
  130. package/build-module/components/global-styles/dimensions-panel.js +3 -7
  131. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  132. package/build-module/components/global-styles/global-styles-provider.js +15 -2
  133. package/build-module/components/global-styles/global-styles-provider.js.map +1 -1
  134. package/build-module/components/global-styles/hooks.js +5 -3
  135. package/build-module/components/global-styles/hooks.js.map +1 -1
  136. package/build-module/components/global-styles/palette.js +1 -1
  137. package/build-module/components/global-styles/palette.js.map +1 -1
  138. package/build-module/components/global-styles/screen-block-list.js +2 -1
  139. package/build-module/components/global-styles/screen-block-list.js.map +1 -1
  140. package/build-module/components/global-styles/screen-block.js +8 -2
  141. package/build-module/components/global-styles/screen-block.js.map +1 -1
  142. package/build-module/components/global-styles/screen-border.js +27 -0
  143. package/build-module/components/global-styles/screen-border.js.map +1 -0
  144. package/build-module/components/global-styles/screen-colors.js +1 -1
  145. package/build-module/components/global-styles/screen-colors.js.map +1 -1
  146. package/build-module/components/global-styles/screen-css.js +28 -0
  147. package/build-module/components/global-styles/screen-css.js.map +1 -0
  148. package/build-module/components/global-styles/screen-layout.js +0 -4
  149. package/build-module/components/global-styles/screen-layout.js.map +1 -1
  150. package/build-module/components/global-styles/screen-root.js +14 -1
  151. package/build-module/components/global-styles/screen-root.js.map +1 -1
  152. package/build-module/components/global-styles/screen-style-variations.js +2 -2
  153. package/build-module/components/global-styles/screen-style-variations.js.map +1 -1
  154. package/build-module/components/global-styles/ui.js +48 -5
  155. package/build-module/components/global-styles/ui.js.map +1 -1
  156. package/build-module/components/global-styles/use-global-styles-output.js +5 -1
  157. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  158. package/build-module/components/global-styles/utils.js +4 -4
  159. package/build-module/components/global-styles/utils.js.map +1 -1
  160. package/build-module/components/{editor/global-styles-renderer.js → global-styles-renderer/index.js} +4 -7
  161. package/build-module/components/global-styles-renderer/index.js.map +1 -0
  162. package/build-module/components/header-edit-mode/document-actions/index.js +13 -6
  163. package/build-module/components/header-edit-mode/document-actions/index.js.map +1 -1
  164. package/build-module/components/header-edit-mode/index.js +16 -11
  165. package/build-module/components/header-edit-mode/index.js.map +1 -1
  166. package/build-module/components/keyboard-shortcuts/index.js +10 -1
  167. package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
  168. package/build-module/components/layout/index.js +203 -0
  169. package/build-module/components/layout/index.js.map +1 -0
  170. package/build-module/components/list/header.js +5 -1
  171. package/build-module/components/list/header.js.map +1 -1
  172. package/build-module/components/list/index.js +4 -19
  173. package/build-module/components/list/index.js.map +1 -1
  174. package/build-module/components/navigate-to-link/index.js +1 -3
  175. package/build-module/components/navigate-to-link/index.js.map +1 -1
  176. package/build-module/components/routes/index.js +1 -1
  177. package/build-module/components/routes/index.js.map +1 -1
  178. package/build-module/components/sidebar/index.js +30 -0
  179. package/build-module/components/sidebar/index.js.map +1 -0
  180. package/build-module/components/sidebar-edit-mode/global-styles-sidebar.js +27 -7
  181. package/build-module/components/sidebar-edit-mode/global-styles-sidebar.js.map +1 -1
  182. package/build-module/components/sidebar-edit-mode/index.js +3 -3
  183. package/build-module/components/sidebar-edit-mode/index.js.map +1 -1
  184. package/build-module/components/sidebar-navigation-item/index.js +40 -0
  185. package/build-module/components/sidebar-navigation-item/index.js.map +1 -0
  186. package/build-module/components/sidebar-navigation-screen/index.js +39 -0
  187. package/build-module/components/sidebar-navigation-screen/index.js.map +1 -0
  188. package/build-module/components/sidebar-navigation-screen-main/index.js +57 -0
  189. package/build-module/components/sidebar-navigation-screen-main/index.js.map +1 -0
  190. package/build-module/components/sidebar-navigation-screen-templates/index.js +165 -0
  191. package/build-module/components/sidebar-navigation-screen-templates/index.js.map +1 -0
  192. package/build-module/components/site-icon/index.js +55 -0
  193. package/build-module/components/site-icon/index.js.map +1 -0
  194. package/build-module/components/site-title/index.js +43 -0
  195. package/build-module/components/site-title/index.js.map +1 -0
  196. package/build-module/components/style-book/index.js +156 -0
  197. package/build-module/components/style-book/index.js.map +1 -0
  198. package/build-module/components/{url-query-controller/index.js → sync-state-with-url/use-init-edited-entity-from-url.js} +4 -3
  199. package/build-module/components/sync-state-with-url/use-init-edited-entity-from-url.js.map +1 -0
  200. package/build-module/components/sync-state-with-url/use-sync-sidebar-path-with-url.js +43 -0
  201. package/build-module/components/sync-state-with-url/use-sync-sidebar-path-with-url.js.map +1 -0
  202. package/build-module/index.js +5 -36
  203. package/build-module/index.js.map +1 -1
  204. package/build-module/store/actions.js +87 -42
  205. package/build-module/store/actions.js.map +1 -1
  206. package/build-module/store/reducer.js +35 -102
  207. package/build-module/store/reducer.js.map +1 -1
  208. package/build-module/store/selectors.js +60 -72
  209. package/build-module/store/selectors.js.map +1 -1
  210. package/build-style/style-rtl.css +550 -346
  211. package/build-style/style.css +550 -346
  212. package/package.json +32 -31
  213. package/src/components/add-new-template/add-custom-template-modal.js +1 -0
  214. package/src/components/add-new-template/index.js +6 -3
  215. package/src/components/add-new-template/new-template-part.js +15 -3
  216. package/src/components/add-new-template/new-template.js +14 -7
  217. package/src/components/add-new-template/style.scss +0 -4
  218. package/src/components/app/index.js +14 -43
  219. package/src/components/block-editor/editor-canvas.js +69 -0
  220. package/src/components/block-editor/index.js +102 -87
  221. package/src/components/block-editor/resizable-editor.js +9 -64
  222. package/src/components/block-editor/style.scss +25 -1
  223. package/src/components/code-editor/style.scss +1 -1
  224. package/src/components/editor/index.js +170 -236
  225. package/src/components/editor/style.scss +0 -22
  226. package/src/components/global-styles/block-preview-panel.js +29 -0
  227. package/src/components/global-styles/context-menu.js +11 -2
  228. package/src/components/global-styles/custom-css.js +73 -0
  229. package/src/components/global-styles/dimensions-panel.js +2 -5
  230. package/src/components/global-styles/global-styles-provider.js +39 -17
  231. package/src/components/global-styles/hooks.js +8 -3
  232. package/src/components/global-styles/palette.js +1 -1
  233. package/src/components/global-styles/screen-block-list.js +2 -1
  234. package/src/components/global-styles/screen-block.js +9 -1
  235. package/src/components/global-styles/screen-border.js +23 -0
  236. package/src/components/global-styles/screen-colors.js +2 -1
  237. package/src/components/global-styles/screen-css.js +33 -0
  238. package/src/components/global-styles/screen-layout.js +0 -3
  239. package/src/components/global-styles/screen-root.js +30 -1
  240. package/src/components/global-styles/screen-style-variations.js +5 -2
  241. package/src/components/global-styles/style.scss +31 -2
  242. package/src/components/global-styles/ui.js +47 -4
  243. package/src/components/global-styles/use-global-styles-output.js +5 -0
  244. package/src/components/global-styles/utils.js +8 -5
  245. package/src/components/{editor/global-styles-renderer.js → global-styles-renderer/index.js} +3 -9
  246. package/src/components/header-edit-mode/document-actions/index.js +14 -9
  247. package/src/components/header-edit-mode/document-actions/style.scss +8 -1
  248. package/src/components/header-edit-mode/index.js +96 -78
  249. package/src/components/header-edit-mode/style.scss +5 -33
  250. package/src/components/keyboard-shortcuts/index.js +13 -0
  251. package/src/components/layout/index.js +278 -0
  252. package/src/components/layout/style.scss +176 -0
  253. package/src/components/list/header.js +5 -1
  254. package/src/components/list/index.js +12 -31
  255. package/src/components/list/style.scss +10 -4
  256. package/src/components/navigate-to-link/index.js +2 -8
  257. package/src/components/routes/index.js +1 -1
  258. package/src/components/sidebar/index.js +34 -0
  259. package/src/components/sidebar/style.scss +8 -0
  260. package/src/components/sidebar-edit-mode/global-styles-sidebar.js +42 -7
  261. package/src/components/sidebar-edit-mode/index.js +3 -3
  262. package/src/components/sidebar-edit-mode/navigation-menu-sidebar/style.scss +21 -3
  263. package/src/components/sidebar-edit-mode/settings-header/style.scss +47 -34
  264. package/src/components/sidebar-edit-mode/style.scss +0 -13
  265. package/src/components/sidebar-navigation-item/index.js +51 -0
  266. package/src/components/sidebar-navigation-item/style.scss +17 -0
  267. package/src/components/sidebar-navigation-screen/index.js +55 -0
  268. package/src/components/sidebar-navigation-screen/style.scss +41 -0
  269. package/src/components/sidebar-navigation-screen-main/index.js +72 -0
  270. package/src/components/sidebar-navigation-screen-templates/index.js +181 -0
  271. package/src/components/sidebar-navigation-screen-templates/style.scss +9 -0
  272. package/src/components/site-icon/index.js +56 -0
  273. package/src/components/site-icon/style.scss +10 -0
  274. package/src/components/site-title/index.js +39 -0
  275. package/src/components/style-book/index.js +193 -0
  276. package/src/components/style-book/style.scss +78 -0
  277. package/src/components/{url-query-controller/index.js → sync-state-with-url/use-init-edited-entity-from-url.js} +3 -3
  278. package/src/components/sync-state-with-url/use-sync-sidebar-path-with-url.js +36 -0
  279. package/src/components/template-details/style.scss +4 -0
  280. package/src/index.js +3 -53
  281. package/src/store/actions.js +93 -48
  282. package/src/store/reducer.js +29 -91
  283. package/src/store/selectors.js +61 -101
  284. package/src/store/test/actions.js +3 -15
  285. package/src/store/test/reducer.js +8 -192
  286. package/src/store/test/selectors.js +3 -42
  287. package/src/style.scss +19 -3
  288. package/build/components/editor/global-styles-renderer.js.map +0 -1
  289. package/build/components/navigation-sidebar/index.js +0 -62
  290. package/build/components/navigation-sidebar/index.js.map +0 -1
  291. package/build/components/navigation-sidebar/navigation-panel/constants.js +0 -77
  292. package/build/components/navigation-sidebar/navigation-panel/constants.js.map +0 -1
  293. package/build/components/navigation-sidebar/navigation-panel/index.js +0 -152
  294. package/build/components/navigation-sidebar/navigation-panel/index.js.map +0 -1
  295. package/build/components/navigation-sidebar/navigation-panel/template-hierarchy.js +0 -81
  296. package/build/components/navigation-sidebar/navigation-panel/template-hierarchy.js.map +0 -1
  297. package/build/components/navigation-sidebar/navigation-toggle/index.js +0 -124
  298. package/build/components/navigation-sidebar/navigation-toggle/index.js.map +0 -1
  299. package/build/components/url-query-controller/index.js.map +0 -1
  300. package/build-module/components/editor/global-styles-renderer.js.map +0 -1
  301. package/build-module/components/navigation-sidebar/index.js +0 -45
  302. package/build-module/components/navigation-sidebar/index.js.map +0 -1
  303. package/build-module/components/navigation-sidebar/navigation-panel/constants.js +0 -49
  304. package/build-module/components/navigation-sidebar/navigation-panel/constants.js.map +0 -1
  305. package/build-module/components/navigation-sidebar/navigation-panel/index.js +0 -131
  306. package/build-module/components/navigation-sidebar/navigation-panel/index.js.map +0 -1
  307. package/build-module/components/navigation-sidebar/navigation-panel/template-hierarchy.js +0 -66
  308. package/build-module/components/navigation-sidebar/navigation-panel/template-hierarchy.js.map +0 -1
  309. package/build-module/components/navigation-sidebar/navigation-toggle/index.js +0 -108
  310. package/build-module/components/navigation-sidebar/navigation-toggle/index.js.map +0 -1
  311. package/build-module/components/url-query-controller/index.js.map +0 -1
  312. package/src/components/navigation-sidebar/index.js +0 -46
  313. package/src/components/navigation-sidebar/navigation-panel/constants.js +0 -94
  314. package/src/components/navigation-sidebar/navigation-panel/index.js +0 -142
  315. package/src/components/navigation-sidebar/navigation-panel/style.scss +0 -152
  316. package/src/components/navigation-sidebar/navigation-panel/template-hierarchy.js +0 -81
  317. package/src/components/navigation-sidebar/navigation-toggle/index.js +0 -114
  318. package/src/components/navigation-sidebar/navigation-toggle/style.scss +0 -71
  319. package/src/components/navigation-sidebar/navigation-toggle/test/index.js +0 -65
package/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 5.0.0 (2022-12-14)
6
+
7
+ ### Breaking Changes
8
+
9
+ - Updated dependencies to require React 18 ([45235](https://github.com/WordPress/gutenberg/pull/45235))
10
+
5
11
  ## 4.19.0 (2022-11-16)
6
12
 
7
13
  ## 4.18.0 (2022-11-02)
@@ -126,6 +126,7 @@ function SuggestionList(_ref2) {
126
126
  }
127
127
 
128
128
  return (0, _element.createElement)(_element.Fragment, null, showSearchControl && (0, _element.createElement)(_components.SearchControl, {
129
+ __nextHasNoMarginBottom: true,
129
130
  onChange: setSearch,
130
131
  value: search,
131
132
  label: labels.search_items,
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/add-custom-template-modal.js"],"names":["EMPTY_ARRAY","SuggestionListItem","suggestion","search","onSelect","entityForSuggestions","composite","baseCssClass","Button","config","getSpecificTemplate","name","link","useDebouncedInput","input","setInput","debounced","setter","setDebounced","useSearchSuggestions","query","order","context","per_page","queryArgs","records","searchResults","hasResolved","searchHasResolved","type","slug","suggestions","setSuggestions","newSuggestions","length","recordNamePath","SuggestionList","orientation","setSearch","debouncedSearch","labels","showSearchControl","setShowSearchControl","search_items","map","not_found","AddCustomTemplateModal","onClose","isCreatingTemplate","showSearchEntities","setShowSearchEntities","hasGeneralTemplate","singular_name","title","description","templatePrefix","template","all_items"],"mappings":";;;;;;;;;AAGA;;;;AACA;;AACA;;AAYA;;AACA;;AACA;;AAKA;;AACA;;AAzBA;AACA;AACA;;AAmBA;AACA;AACA;AAIA,MAAMA,WAAW,GAAG,EAApB;;AAEA,SAASC,kBAAT,OAMI;AAAA,MANyB;AAC5BC,IAAAA,UAD4B;AAE5BC,IAAAA,MAF4B;AAG5BC,IAAAA,QAH4B;AAI5BC,IAAAA,oBAJ4B;AAK5BC,IAAAA;AAL4B,GAMzB;AACH,QAAMC,YAAY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EAAG,MAAM;AACf0C,MAAAA,qBAAqB,CAAE,IAAF,CAArB;AACA;AALF,KAOC,4BAAC,8BAAD;AAAM,IAAA,EAAE,EAAC,MAAT;AAAgB,IAAA,MAAM,EAAG;AAAzB,KACG7C,oBAAoB,CAACmC,MAArB,CAA4BY,aAD/B,CAPD,EAUC,4BAAC,8BAAD;AAAM,IAAA,EAAE,EAAC;AAAT,KAEE;AACA,gBAAI,qBAAJ,CAHF,CAVD,CAjCD,CAND,CAZF,EAuEGH,kBAAkB,IACnB,qDACC,uCACG,cACD,+DADC,CADH,CADD,EAMC,4BAAC,cAAD;AACC,IAAA,oBAAoB,EAAG5C,oBADxB;AAEC,IAAA,QAAQ,EAAGD;AAFZ,IAND,CAxEF,CADD;AAuFA;;eAEc0C,sB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useMemo, useEffect } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tButton,\n\tFlex,\n\tFlexItem,\n\tModal,\n\tSearchControl,\n\tTextHighlight,\n\t__experimentalText as Text,\n\t__unstableComposite as Composite,\n\t__unstableUseCompositeState as useCompositeState,\n\t__unstableCompositeItem as CompositeItem,\n} from '@wordpress/components';\nimport { useDebounce } from '@wordpress/compose';\nimport { useEntityRecords } from '@wordpress/core-data';\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport TemplateActionsLoadingScreen from './template-actions-loading-screen';\nimport { mapToIHasNameAndId } from './utils';\n\nconst EMPTY_ARRAY = [];\n\nfunction SuggestionListItem( {\n\tsuggestion,\n\tsearch,\n\tonSelect,\n\tentityForSuggestions,\n\tcomposite,\n} ) {\n\tconst baseCssClass =\n\t\t'edit-site-custom-template-modal__suggestions_list__list-item';\n\treturn (\n\t\t<CompositeItem\n\t\t\trole=\"option\"\n\t\t\tas={ Button }\n\t\t\t{ ...composite }\n\t\t\tclassName={ baseCssClass }\n\t\t\tonClick={ () =>\n\t\t\t\tonSelect(\n\t\t\t\t\tentityForSuggestions.config.getSpecificTemplate(\n\t\t\t\t\t\tsuggestion\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t}\n\t\t>\n\t\t\t<span className={ `${ baseCssClass }__title` }>\n\t\t\t\t<TextHighlight\n\t\t\t\t\ttext={ decodeEntities( suggestion.name ) }\n\t\t\t\t\thighlight={ search }\n\t\t\t\t/>\n\t\t\t</span>\n\t\t\t{ suggestion.link && (\n\t\t\t\t<span className={ `${ baseCssClass }__info` }>\n\t\t\t\t\t{ suggestion.link }\n\t\t\t\t</span>\n\t\t\t) }\n\t\t</CompositeItem>\n\t);\n}\n\nfunction useDebouncedInput() {\n\tconst [ input, setInput ] = useState( '' );\n\tconst [ debounced, setter ] = useState( '' );\n\tconst setDebounced = useDebounce( setter, 250 );\n\tuseEffect( () => {\n\t\tif ( debounced !== input ) {\n\t\t\tsetDebounced( input );\n\t\t}\n\t}, [ debounced, input ] );\n\treturn [ input, setInput, debounced ];\n}\n\nfunction useSearchSuggestions( entityForSuggestions, search ) {\n\tconst { config } = entityForSuggestions;\n\tconst query = useMemo(\n\t\t() => ( {\n\t\t\torder: 'asc',\n\t\t\tcontext: 'view',\n\t\t\tsearch,\n\t\t\tper_page: search ? 20 : 10,\n\t\t\t...config.queryArgs( search ),\n\t\t} ),\n\t\t[ search, config ]\n\t);\n\tconst { records: searchResults, hasResolved: searchHasResolved } =\n\t\tuseEntityRecords(\n\t\t\tentityForSuggestions.type,\n\t\t\tentityForSuggestions.slug,\n\t\t\tquery\n\t\t);\n\tconst [ suggestions, setSuggestions ] = useState( EMPTY_ARRAY );\n\tuseEffect( () => {\n\t\tif ( ! searchHasResolved ) return;\n\t\tlet newSuggestions = EMPTY_ARRAY;\n\t\tif ( searchResults?.length ) {\n\t\t\tnewSuggestions = searchResults;\n\t\t\tif ( config.recordNamePath ) {\n\t\t\t\tnewSuggestions = mapToIHasNameAndId(\n\t\t\t\t\tnewSuggestions,\n\t\t\t\t\tconfig.recordNamePath\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\t// Update suggestions only when the query has resolved, so as to keep\n\t\t// the previous results in the UI.\n\t\tsetSuggestions( newSuggestions );\n\t}, [ searchResults, searchHasResolved ] );\n\treturn suggestions;\n}\n\nfunction SuggestionList( { entityForSuggestions, onSelect } ) {\n\tconst composite = useCompositeState( { orientation: 'vertical' } );\n\tconst [ search, setSearch, debouncedSearch ] = useDebouncedInput();\n\tconst suggestions = useSearchSuggestions(\n\t\tentityForSuggestions,\n\t\tdebouncedSearch\n\t);\n\tconst { labels } = entityForSuggestions;\n\tconst [ showSearchControl, setShowSearchControl ] = useState( false );\n\tif ( ! showSearchControl && suggestions?.length > 9 ) {\n\t\tsetShowSearchControl( true );\n\t}\n\treturn (\n\t\t<>\n\t\t\t{ showSearchControl && (\n\t\t\t\t<SearchControl\n\t\t\t\t\tonChange={ setSearch }\n\t\t\t\t\tvalue={ search }\n\t\t\t\t\tlabel={ labels.search_items }\n\t\t\t\t\tplaceholder={ labels.search_items }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ !! suggestions?.length && (\n\t\t\t\t<Composite\n\t\t\t\t\t{ ...composite }\n\t\t\t\t\trole=\"listbox\"\n\t\t\t\t\tclassName=\"edit-site-custom-template-modal__suggestions_list\"\n\t\t\t\t\taria-label={ __( 'Suggestions list' ) }\n\t\t\t\t>\n\t\t\t\t\t{ suggestions.map( ( suggestion ) => (\n\t\t\t\t\t\t<SuggestionListItem\n\t\t\t\t\t\t\tkey={ suggestion.slug }\n\t\t\t\t\t\t\tsuggestion={ suggestion }\n\t\t\t\t\t\t\tsearch={ debouncedSearch }\n\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\t\tcomposite={ composite }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t</Composite>\n\t\t\t) }\n\t\t\t{ debouncedSearch && ! suggestions?.length && (\n\t\t\t\t<p className=\"edit-site-custom-template-modal__no-results\">\n\t\t\t\t\t{ labels.not_found }\n\t\t\t\t</p>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction AddCustomTemplateModal( {\n\tonClose,\n\tonSelect,\n\tentityForSuggestions,\n\tisCreatingTemplate,\n} ) {\n\tconst [ showSearchEntities, setShowSearchEntities ] = useState(\n\t\tentityForSuggestions.hasGeneralTemplate\n\t);\n\tconst baseCssClass = 'edit-site-custom-template-modal';\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ sprintf(\n\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t__( 'Add template: %s' ),\n\t\t\t\tentityForSuggestions.labels.singular_name\n\t\t\t) }\n\t\t\tclassName={ baseCssClass }\n\t\t\tcloseLabel={ __( 'Close' ) }\n\t\t\tonRequestClose={ onClose }\n\t\t>\n\t\t\t{ isCreatingTemplate && <TemplateActionsLoadingScreen /> }\n\t\t\t{ ! showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Select whether to create a single template for all items or a specific one.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t\t<Flex\n\t\t\t\t\t\tclassName={ `${ baseCssClass }__contents` }\n\t\t\t\t\t\tgap=\"4\"\n\t\t\t\t\t\talign=\"initial\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\ttemplatePrefix,\n\t\t\t\t\t\t\t\t} = entityForSuggestions.template;\n\t\t\t\t\t\t\t\tonSelect( {\n\t\t\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\ttemplatePrefix,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Text as=\"span\" weight={ 600 }>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.all_items }\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t\t<Text as=\"span\">\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.\n\t\t\t\t\t\t\t\t\t__( 'For all items' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetShowSearchEntities( true );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Text as=\"span\" weight={ 600 }>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.singular_name }\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t\t<Text as=\"span\">\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.\n\t\t\t\t\t\t\t\t\t__( 'For a specific item' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t</Flex>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'This template will be used only for the specific item chosen.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t\t<SuggestionList\n\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</Modal>\n\t);\n}\n\nexport default AddCustomTemplateModal;\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/add-custom-template-modal.js"],"names":["EMPTY_ARRAY","SuggestionListItem","suggestion","search","onSelect","entityForSuggestions","composite","baseCssClass","Button","config","getSpecificTemplate","name","link","useDebouncedInput","input","setInput","debounced","setter","setDebounced","useSearchSuggestions","query","order","context","per_page","queryArgs","records","searchResults","hasResolved","searchHasResolved","type","slug","suggestions","setSuggestions","newSuggestions","length","recordNamePath","SuggestionList","orientation","setSearch","debouncedSearch","labels","showSearchControl","setShowSearchControl","search_items","map","not_found","AddCustomTemplateModal","onClose","isCreatingTemplate","showSearchEntities","setShowSearchEntities","hasGeneralTemplate","singular_name","title","description","templatePrefix","template","all_items"],"mappings":";;;;;;;;;AAGA;;;;AACA;;AACA;;AAYA;;AACA;;AACA;;AAKA;;AACA;;AAzBA;AACA;AACA;;AAmBA;AACA;AACA;AAIA,MAAMA,WAAW,GAAG,EAApB;;AAEA,SAASC,kBAAT,OAMI;AAAA,MANyB;AAC5BC,IAAAA,UAD4B;AAE5BC,IAAAA,MAF4B;AAG5BC,IAAAA,QAH4B;AAI5BC,IAAAA,oBAJ4B;AAK5BC,IAAAA;AAL4B,GAMzB;AACH,QAAMC,YAAY,GACjB,8DADD;AAEA,SACC,4BAAC,mCAAD;AACC,IAAA,IAAI,EAAC,QADN;AAEC,IAAA,EAAE,EAAGC;AAFN,KAGMF,SAHN;AAIC,IAAA,SAAS,EAAGC,YAJb;AAKC,IAAA,OAAO,EAAG,MACTH,QAAQ,CACPC,oBAAoB,CAACI,MAArB,CAA4BC,mBAA5B,CACCR,UADD,CADO;AANV,MAaC;AAAM,IAAA,SAAS,EAAI,GAAGK,YAAc;AAApC,KACC,4BAAC,yBAAD;AACC,IAAA,IAAI,EAAG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uEGH,kBAAkB,IACnB,qDACC,uCACG,cACD,+DADC,CADH,CADD,EAMC,4BAAC,cAAD;AACC,IAAA,oBAAoB,EAAG5C,oBADxB;AAEC,IAAA,QAAQ,EAAGD;AAFZ,IAND,CAxEF,CADD;AAuFA;;eAEc0C,sB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useMemo, useEffect } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tButton,\n\tFlex,\n\tFlexItem,\n\tModal,\n\tSearchControl,\n\tTextHighlight,\n\t__experimentalText as Text,\n\t__unstableComposite as Composite,\n\t__unstableUseCompositeState as useCompositeState,\n\t__unstableCompositeItem as CompositeItem,\n} from '@wordpress/components';\nimport { useDebounce } from '@wordpress/compose';\nimport { useEntityRecords } from '@wordpress/core-data';\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport TemplateActionsLoadingScreen from './template-actions-loading-screen';\nimport { mapToIHasNameAndId } from './utils';\n\nconst EMPTY_ARRAY = [];\n\nfunction SuggestionListItem( {\n\tsuggestion,\n\tsearch,\n\tonSelect,\n\tentityForSuggestions,\n\tcomposite,\n} ) {\n\tconst baseCssClass =\n\t\t'edit-site-custom-template-modal__suggestions_list__list-item';\n\treturn (\n\t\t<CompositeItem\n\t\t\trole=\"option\"\n\t\t\tas={ Button }\n\t\t\t{ ...composite }\n\t\t\tclassName={ baseCssClass }\n\t\t\tonClick={ () =>\n\t\t\t\tonSelect(\n\t\t\t\t\tentityForSuggestions.config.getSpecificTemplate(\n\t\t\t\t\t\tsuggestion\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t}\n\t\t>\n\t\t\t<span className={ `${ baseCssClass }__title` }>\n\t\t\t\t<TextHighlight\n\t\t\t\t\ttext={ decodeEntities( suggestion.name ) }\n\t\t\t\t\thighlight={ search }\n\t\t\t\t/>\n\t\t\t</span>\n\t\t\t{ suggestion.link && (\n\t\t\t\t<span className={ `${ baseCssClass }__info` }>\n\t\t\t\t\t{ suggestion.link }\n\t\t\t\t</span>\n\t\t\t) }\n\t\t</CompositeItem>\n\t);\n}\n\nfunction useDebouncedInput() {\n\tconst [ input, setInput ] = useState( '' );\n\tconst [ debounced, setter ] = useState( '' );\n\tconst setDebounced = useDebounce( setter, 250 );\n\tuseEffect( () => {\n\t\tif ( debounced !== input ) {\n\t\t\tsetDebounced( input );\n\t\t}\n\t}, [ debounced, input ] );\n\treturn [ input, setInput, debounced ];\n}\n\nfunction useSearchSuggestions( entityForSuggestions, search ) {\n\tconst { config } = entityForSuggestions;\n\tconst query = useMemo(\n\t\t() => ( {\n\t\t\torder: 'asc',\n\t\t\tcontext: 'view',\n\t\t\tsearch,\n\t\t\tper_page: search ? 20 : 10,\n\t\t\t...config.queryArgs( search ),\n\t\t} ),\n\t\t[ search, config ]\n\t);\n\tconst { records: searchResults, hasResolved: searchHasResolved } =\n\t\tuseEntityRecords(\n\t\t\tentityForSuggestions.type,\n\t\t\tentityForSuggestions.slug,\n\t\t\tquery\n\t\t);\n\tconst [ suggestions, setSuggestions ] = useState( EMPTY_ARRAY );\n\tuseEffect( () => {\n\t\tif ( ! searchHasResolved ) return;\n\t\tlet newSuggestions = EMPTY_ARRAY;\n\t\tif ( searchResults?.length ) {\n\t\t\tnewSuggestions = searchResults;\n\t\t\tif ( config.recordNamePath ) {\n\t\t\t\tnewSuggestions = mapToIHasNameAndId(\n\t\t\t\t\tnewSuggestions,\n\t\t\t\t\tconfig.recordNamePath\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\t// Update suggestions only when the query has resolved, so as to keep\n\t\t// the previous results in the UI.\n\t\tsetSuggestions( newSuggestions );\n\t}, [ searchResults, searchHasResolved ] );\n\treturn suggestions;\n}\n\nfunction SuggestionList( { entityForSuggestions, onSelect } ) {\n\tconst composite = useCompositeState( { orientation: 'vertical' } );\n\tconst [ search, setSearch, debouncedSearch ] = useDebouncedInput();\n\tconst suggestions = useSearchSuggestions(\n\t\tentityForSuggestions,\n\t\tdebouncedSearch\n\t);\n\tconst { labels } = entityForSuggestions;\n\tconst [ showSearchControl, setShowSearchControl ] = useState( false );\n\tif ( ! showSearchControl && suggestions?.length > 9 ) {\n\t\tsetShowSearchControl( true );\n\t}\n\treturn (\n\t\t<>\n\t\t\t{ showSearchControl && (\n\t\t\t\t<SearchControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tonChange={ setSearch }\n\t\t\t\t\tvalue={ search }\n\t\t\t\t\tlabel={ labels.search_items }\n\t\t\t\t\tplaceholder={ labels.search_items }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ !! suggestions?.length && (\n\t\t\t\t<Composite\n\t\t\t\t\t{ ...composite }\n\t\t\t\t\trole=\"listbox\"\n\t\t\t\t\tclassName=\"edit-site-custom-template-modal__suggestions_list\"\n\t\t\t\t\taria-label={ __( 'Suggestions list' ) }\n\t\t\t\t>\n\t\t\t\t\t{ suggestions.map( ( suggestion ) => (\n\t\t\t\t\t\t<SuggestionListItem\n\t\t\t\t\t\t\tkey={ suggestion.slug }\n\t\t\t\t\t\t\tsuggestion={ suggestion }\n\t\t\t\t\t\t\tsearch={ debouncedSearch }\n\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\t\tcomposite={ composite }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t</Composite>\n\t\t\t) }\n\t\t\t{ debouncedSearch && ! suggestions?.length && (\n\t\t\t\t<p className=\"edit-site-custom-template-modal__no-results\">\n\t\t\t\t\t{ labels.not_found }\n\t\t\t\t</p>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction AddCustomTemplateModal( {\n\tonClose,\n\tonSelect,\n\tentityForSuggestions,\n\tisCreatingTemplate,\n} ) {\n\tconst [ showSearchEntities, setShowSearchEntities ] = useState(\n\t\tentityForSuggestions.hasGeneralTemplate\n\t);\n\tconst baseCssClass = 'edit-site-custom-template-modal';\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ sprintf(\n\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t__( 'Add template: %s' ),\n\t\t\t\tentityForSuggestions.labels.singular_name\n\t\t\t) }\n\t\t\tclassName={ baseCssClass }\n\t\t\tcloseLabel={ __( 'Close' ) }\n\t\t\tonRequestClose={ onClose }\n\t\t>\n\t\t\t{ isCreatingTemplate && <TemplateActionsLoadingScreen /> }\n\t\t\t{ ! showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Select whether to create a single template for all items or a specific one.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t\t<Flex\n\t\t\t\t\t\tclassName={ `${ baseCssClass }__contents` }\n\t\t\t\t\t\tgap=\"4\"\n\t\t\t\t\t\talign=\"initial\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\ttemplatePrefix,\n\t\t\t\t\t\t\t\t} = entityForSuggestions.template;\n\t\t\t\t\t\t\t\tonSelect( {\n\t\t\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\ttemplatePrefix,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Text as=\"span\" weight={ 600 }>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.all_items }\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t\t<Text as=\"span\">\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.\n\t\t\t\t\t\t\t\t\t__( 'For all items' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetShowSearchEntities( true );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Text as=\"span\" weight={ 600 }>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.singular_name }\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t\t<Text as=\"span\">\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.\n\t\t\t\t\t\t\t\t\t__( 'For a specific item' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t</Flex>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'This template will be used only for the specific item chosen.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t\t<SuggestionList\n\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</Modal>\n\t);\n}\n\nexport default AddCustomTemplateModal;\n"]}
@@ -9,6 +9,8 @@ exports.default = AddNewTemplate;
9
9
 
10
10
  var _element = require("@wordpress/element");
11
11
 
12
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
+
12
14
  var _data = require("@wordpress/data");
13
15
 
14
16
  var _coreData = require("@wordpress/core-data");
@@ -26,7 +28,8 @@ var _newTemplatePart = _interopRequireDefault(require("./new-template-part"));
26
28
  */
27
29
  function AddNewTemplate(_ref) {
28
30
  let {
29
- templateType = 'wp_template'
31
+ templateType = 'wp_template',
32
+ ...props
30
33
  } = _ref;
31
34
  const postType = (0, _data.useSelect)(select => select(_coreData.store).getPostType(templateType), [templateType]);
32
35
 
@@ -35,13 +38,13 @@ function AddNewTemplate(_ref) {
35
38
  }
36
39
 
37
40
  if (templateType === 'wp_template') {
38
- return (0, _element.createElement)(_newTemplate.default, {
41
+ return (0, _element.createElement)(_newTemplate.default, (0, _extends2.default)({}, props, {
39
42
  postType: postType
40
- });
43
+ }));
41
44
  } else if (templateType === 'wp_template_part') {
42
- return (0, _element.createElement)(_newTemplatePart.default, {
45
+ return (0, _element.createElement)(_newTemplatePart.default, (0, _extends2.default)({}, props, {
43
46
  postType: postType
44
- });
47
+ }));
45
48
  }
46
49
 
47
50
  return null;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/index.js"],"names":["AddNewTemplate","templateType","postType","select","coreStore","getPostType"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAVA;AACA;AACA;;AAIA;AACA;AACA;AAIe,SAASA,cAAT,OAA4D;AAAA,MAAnC;AAAEC,IAAAA,YAAY,GAAG;AAAjB,GAAmC;AAC1E,QAAMC,QAAQ,GAAG,qBACdC,MAAF,IAAcA,MAAM,CAAEC,eAAF,CAAN,CAAoBC,WAApB,CAAiCJ,YAAjC,CADE,EAEhB,CAAEA,YAAF,CAFgB,CAAjB;;AAKA,MAAK,CAAEC,QAAP,EAAkB;AACjB,WAAO,IAAP;AACA;;AAED,MAAKD,YAAY,KAAK,aAAtB,EAAsC;AACrC,WAAO,4BAAC,oBAAD;AAAa,MAAA,QAAQ,EAAGC;AAAxB,MAAP;AACA,GAFD,MAEO,IAAKD,YAAY,KAAK,kBAAtB,EAA2C;AACjD,WAAO,4BAAC,wBAAD;AAAiB,MAAA,QAAQ,EAAGC;AAA5B,MAAP;AACA;;AAED,SAAO,IAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport NewTemplate from './new-template';\nimport NewTemplatePart from './new-template-part';\n\nexport default function AddNewTemplate( { templateType = 'wp_template' } ) {\n\tconst postType = useSelect(\n\t\t( select ) => select( coreStore ).getPostType( templateType ),\n\t\t[ templateType ]\n\t);\n\n\tif ( ! postType ) {\n\t\treturn null;\n\t}\n\n\tif ( templateType === 'wp_template' ) {\n\t\treturn <NewTemplate postType={ postType } />;\n\t} else if ( templateType === 'wp_template_part' ) {\n\t\treturn <NewTemplatePart postType={ postType } />;\n\t}\n\n\treturn null;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/index.js"],"names":["AddNewTemplate","templateType","props","postType","select","coreStore","getPostType"],"mappings":";;;;;;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAVA;AACA;AACA;;AAIA;AACA;AACA;AAIe,SAASA,cAAT,OAGX;AAAA,MAHoC;AACvCC,IAAAA,YAAY,GAAG,aADwB;AAEvC,OAAGC;AAFoC,GAGpC;AACH,QAAMC,QAAQ,GAAG,qBACdC,MAAF,IAAcA,MAAM,CAAEC,eAAF,CAAN,CAAoBC,WAApB,CAAiCL,YAAjC,CADE,EAEhB,CAAEA,YAAF,CAFgB,CAAjB;;AAKA,MAAK,CAAEE,QAAP,EAAkB;AACjB,WAAO,IAAP;AACA;;AAED,MAAKF,YAAY,KAAK,aAAtB,EAAsC;AACrC,WAAO,4BAAC,oBAAD,6BAAkBC,KAAlB;AAA0B,MAAA,QAAQ,EAAGC;AAArC,OAAP;AACA,GAFD,MAEO,IAAKF,YAAY,KAAK,kBAAtB,EAA2C;AACjD,WAAO,4BAAC,wBAAD,6BAAsBC,KAAtB;AAA8B,MAAA,QAAQ,EAAGC;AAAzC,OAAP;AACA;;AAED,SAAO,IAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport NewTemplate from './new-template';\nimport NewTemplatePart from './new-template-part';\n\nexport default function AddNewTemplate( {\n\ttemplateType = 'wp_template',\n\t...props\n} ) {\n\tconst postType = useSelect(\n\t\t( select ) => select( coreStore ).getPostType( templateType ),\n\t\t[ templateType ]\n\t);\n\n\tif ( ! postType ) {\n\t\treturn null;\n\t}\n\n\tif ( templateType === 'wp_template' ) {\n\t\treturn <NewTemplate { ...props } postType={ postType } />;\n\t} else if ( templateType === 'wp_template_part' ) {\n\t\treturn <NewTemplatePart { ...props } postType={ postType } />;\n\t}\n\n\treturn null;\n}\n"]}
@@ -9,6 +9,8 @@ exports.default = NewTemplatePart;
9
9
 
10
10
  var _element = require("@wordpress/element");
11
11
 
12
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
+
12
14
  var _lodash = require("lodash");
13
15
 
14
16
  var _data = require("@wordpress/data");
@@ -21,8 +23,12 @@ var _notices = require("@wordpress/notices");
21
23
 
22
24
  var _coreData = require("@wordpress/core-data");
23
25
 
26
+ var _icons = require("@wordpress/icons");
27
+
24
28
  var _routes = require("../routes");
25
29
 
30
+ var _store = require("../../store");
31
+
26
32
  var _createTemplatePartModal = _interopRequireDefault(require("../create-template-part-modal"));
27
33
 
28
34
  /**
@@ -38,7 +44,9 @@ var _createTemplatePartModal = _interopRequireDefault(require("../create-templat
38
44
  */
39
45
  function NewTemplatePart(_ref) {
40
46
  let {
41
- postType
47
+ postType,
48
+ showIcon = true,
49
+ toggleProps
42
50
  } = _ref;
43
51
  const history = (0, _routes.useHistory)();
44
52
  const [isModalOpen, setIsModalOpen] = (0, _element.useState)(false);
@@ -48,6 +56,9 @@ function NewTemplatePart(_ref) {
48
56
  const {
49
57
  saveEntityRecord
50
58
  } = (0, _data.useDispatch)(_coreData.store);
59
+ const {
60
+ __unstableSetCanvasMode
61
+ } = (0, _data.useDispatch)(_store.store);
51
62
 
52
63
  async function createTemplatePart(_ref2) {
53
64
  let {
@@ -74,7 +85,10 @@ function NewTemplatePart(_ref) {
74
85
  }, {
75
86
  throwOnError: true
76
87
  });
77
- setIsModalOpen(false); // Navigate to the created template part editor.
88
+ setIsModalOpen(false); // Switch to edit mode.
89
+
90
+ __unstableSetCanvasMode('edit'); // Navigate to the created template part editor.
91
+
78
92
 
79
93
  history.push({
80
94
  postId: templatePart.id,
@@ -89,12 +103,13 @@ function NewTemplatePart(_ref) {
89
103
  }
90
104
  }
91
105
 
92
- return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_components.Button, {
93
- variant: "primary",
106
+ return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_components.Button, (0, _extends2.default)({}, toggleProps, {
94
107
  onClick: () => {
95
108
  setIsModalOpen(true);
96
- }
97
- }, postType.labels.add_new), isModalOpen && (0, _element.createElement)(_createTemplatePartModal.default, {
109
+ },
110
+ icon: showIcon ? _icons.plus : null,
111
+ label: postType.labels.add_new
112
+ }), showIcon ? null : postType.labels.add_new), isModalOpen && (0, _element.createElement)(_createTemplatePartModal.default, {
98
113
  closeModal: () => setIsModalOpen(false),
99
114
  onCreate: createTemplatePart
100
115
  }));
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template-part.js"],"names":["NewTemplatePart","postType","history","isModalOpen","setIsModalOpen","createErrorNotice","noticesStore","saveEntityRecord","coreStore","createTemplatePart","title","area","type","cleanSlug","replace","templatePart","slug","content","throwOnError","push","postId","id","error","errorMessage","message","code","labels","add_new"],"mappings":";;;;;;;;;AAQA;;AALA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAnBA;AACA;AACA;;AAGA;AACA;AACA;;AAQA;AACA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T,GAEG,cACA,qDADA,CAHJ;AAOAnB,MAAAA,iBAAiB,CAAEkB,YAAF,EAAgB;AAAEX,QAAAA,IAAI,EAAE;AAAR,OAAhB,CAAjB;AAEAR,MAAAA,cAAc,CAAE,KAAF,CAAd;AACA;AACD;;AAED,SACC,qDACC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,OAAO,EAAG,MAAM;AACfA,MAAAA,cAAc,CAAE,IAAF,CAAd;AACA;AAJF,KAMGH,QAAQ,CAACyB,MAAT,CAAgBC,OANnB,CADD,EASGxB,WAAW,IACZ,4BAAC,gCAAD;AACC,IAAA,UAAU,EAAG,MAAMC,cAAc,CAAE,KAAF,CADlC;AAEC,IAAA,QAAQ,EAAGK;AAFZ,IAVF,CADD;AAkBA","sourcesContent":["/**\n * External dependencies\n */\nimport { kebabCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { useHistory } from '../routes';\nimport CreateTemplatePartModal from '../create-template-part-modal';\n\nexport default function NewTemplatePart( { postType } ) {\n\tconst history = useHistory();\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\n\tasync function createTemplatePart( { title, area } ) {\n\t\tif ( ! title ) {\n\t\t\tcreateErrorNotice( __( 'Title is not defined.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\t// Currently template parts only allow latin chars.\n\t\t\t// Fallback slug will receive suffix by default.\n\t\t\tconst cleanSlug =\n\t\t\t\tkebabCase( title ).replace( /[^\\w-]+/g, '' ) ||\n\t\t\t\t'wp-custom-part';\n\n\t\t\tconst templatePart = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template_part',\n\t\t\t\t{\n\t\t\t\t\tslug: cleanSlug,\n\t\t\t\t\ttitle,\n\t\t\t\t\tcontent: '',\n\t\t\t\t\tarea,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\tsetIsModalOpen( false );\n\n\t\t\t// Navigate to the created template part editor.\n\t\t\thistory.push( {\n\t\t\t\tpostId: templatePart.id,\n\t\t\t\tpostType: templatePart.type,\n\t\t\t} );\n\n\t\t\t// TODO: Add a success notice?\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __(\n\t\t\t\t\t\t\t'An error occurred while creating the template part.'\n\t\t\t\t\t );\n\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\n\t\t\tsetIsModalOpen( false );\n\t\t}\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tvariant=\"primary\"\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tsetIsModalOpen( true );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ postType.labels.add_new }\n\t\t\t</Button>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<CreateTemplatePartModal\n\t\t\t\t\tcloseModal={ () => setIsModalOpen( false ) }\n\t\t\t\t\tonCreate={ createTemplatePart }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template-part.js"],"names":["NewTemplatePart","postType","showIcon","toggleProps","history","isModalOpen","setIsModalOpen","createErrorNotice","noticesStore","saveEntityRecord","coreStore","__unstableSetCanvasMode","editSiteStore","createTemplatePart","title","area","type","cleanSlug","replace","templatePart","slug","content","throwOnError","push","postId","id","error","errorMessage","message","code","plus","labels","add_new"],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G,CAwBH;;;AACAP,MAAAA,OAAO,CAACmB,IAAR,CAAc;AACbC,QAAAA,MAAM,EAAEL,YAAY,CAACM,EADR;AAEbxB,QAAAA,QAAQ,EAAEkB,YAAY,CAACH;AAFV,OAAd,EAzBG,CA8BH;AACA,KA/BD,CA+BE,OAAQU,KAAR,EAAgB;AACjB,YAAMC,YAAY,GACjBD,KAAK,CAACE,OAAN,IAAiBF,KAAK,CAACG,IAAN,KAAe,eAAhC,GACGH,KAAK,CAACE,OADT,GAEG,cACA,qDADA,CAHJ;AAOArB,MAAAA,iBAAiB,CAAEoB,YAAF,EAAgB;AAAEX,QAAAA,IAAI,EAAE;AAAR,OAAhB,CAAjB;AAEAV,MAAAA,cAAc,CAAE,KAAF,CAAd;AACA;AACD;;AAED,SACC,qDACC,4BAAC,kBAAD,6BACMH,WADN;AAEC,IAAA,OAAO,EAAG,MAAM;AACfG,MAAAA,cAAc,CAAE,IAAF,CAAd;AACA,KAJF;AAKC,IAAA,IAAI,EAAGJ,QAAQ,GAAG4B,WAAH,GAAU,IAL1B;AAMC,IAAA,KAAK,EAAG7B,QAAQ,CAAC8B,MAAT,CAAgBC;AANzB,MAQG9B,QAAQ,GAAG,IAAH,GAAUD,QAAQ,CAAC8B,MAAT,CAAgBC,OARrC,CADD,EAWG3B,WAAW,IACZ,4BAAC,gCAAD;AACC,IAAA,UAAU,EAAG,MAAMC,cAAc,CAAE,KAAF,CADlC;AAEC,IAAA,QAAQ,EAAGO;AAFZ,IAZF,CADD;AAoBA","sourcesContent":["/**\n * External dependencies\n */\nimport { kebabCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { plus } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { useHistory } from '../routes';\nimport { store as editSiteStore } from '../../store';\nimport CreateTemplatePartModal from '../create-template-part-modal';\n\nexport default function NewTemplatePart( {\n\tpostType,\n\tshowIcon = true,\n\ttoggleProps,\n} ) {\n\tconst history = useHistory();\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { __unstableSetCanvasMode } = useDispatch( editSiteStore );\n\n\tasync function createTemplatePart( { title, area } ) {\n\t\tif ( ! title ) {\n\t\t\tcreateErrorNotice( __( 'Title is not defined.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\t// Currently template parts only allow latin chars.\n\t\t\t// Fallback slug will receive suffix by default.\n\t\t\tconst cleanSlug =\n\t\t\t\tkebabCase( title ).replace( /[^\\w-]+/g, '' ) ||\n\t\t\t\t'wp-custom-part';\n\n\t\t\tconst templatePart = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template_part',\n\t\t\t\t{\n\t\t\t\t\tslug: cleanSlug,\n\t\t\t\t\ttitle,\n\t\t\t\t\tcontent: '',\n\t\t\t\t\tarea,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\tsetIsModalOpen( false );\n\n\t\t\t// Switch to edit mode.\n\t\t\t__unstableSetCanvasMode( 'edit' );\n\n\t\t\t// Navigate to the created template part editor.\n\t\t\thistory.push( {\n\t\t\t\tpostId: templatePart.id,\n\t\t\t\tpostType: templatePart.type,\n\t\t\t} );\n\n\t\t\t// TODO: Add a success notice?\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __(\n\t\t\t\t\t\t\t'An error occurred while creating the template part.'\n\t\t\t\t\t );\n\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\n\t\t\tsetIsModalOpen( false );\n\t\t}\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<Button\n\t\t\t\t{ ...toggleProps }\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tsetIsModalOpen( true );\n\t\t\t\t} }\n\t\t\t\ticon={ showIcon ? plus : null }\n\t\t\t\tlabel={ postType.labels.add_new }\n\t\t\t>\n\t\t\t\t{ showIcon ? null : postType.labels.add_new }\n\t\t\t</Button>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<CreateTemplatePartModal\n\t\t\t\t\tcloseModal={ () => setIsModalOpen( false ) }\n\t\t\t\t\tonCreate={ createTemplatePart }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
@@ -63,7 +63,9 @@ const TEMPLATE_ICONS = {
63
63
 
64
64
  function NewTemplate(_ref) {
65
65
  let {
66
- postType
66
+ postType,
67
+ toggleProps,
68
+ showIcon = true
67
69
  } = _ref;
68
70
  const [showCustomTemplateModal, setShowCustomTemplateModal] = (0, _element.useState)(false);
69
71
  const [showCustomGenericTemplateModal, setShowCustomGenericTemplateModal] = (0, _element.useState)(false);
@@ -78,7 +80,8 @@ function NewTemplate(_ref) {
78
80
  createSuccessNotice
79
81
  } = (0, _data.useDispatch)(_notices.store);
80
82
  const {
81
- setTemplate
83
+ setTemplate,
84
+ __unstableSetCanvasMode
82
85
  } = (0, _data.useDispatch)(_store.store);
83
86
 
84
87
  async function createTemplate(template) {
@@ -123,7 +126,10 @@ function NewTemplate(_ref) {
123
126
  throwOnError: true
124
127
  }); // Set template before navigating away to avoid initial stale value.
125
128
 
126
- setTemplate(newTemplate.id, newTemplate.slug); // Navigate to the created template editor.
129
+ setTemplate(newTemplate.id, newTemplate.slug); // Switch to edit mode.
130
+
131
+ __unstableSetCanvasMode('edit'); // Navigate to the created template editor.
132
+
127
133
 
128
134
  history.push({
129
135
  postId: newTemplate.id,
@@ -151,15 +157,13 @@ function NewTemplate(_ref) {
151
157
 
152
158
  return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_components.DropdownMenu, {
153
159
  className: "edit-site-new-template-dropdown",
154
- icon: null,
155
- text: postType.labels.add_new,
160
+ icon: showIcon ? _icons.plus : null,
161
+ text: showIcon ? null : postType.labels.add_new,
156
162
  label: postType.labels.add_new_item,
157
163
  popoverProps: {
158
164
  noArrow: false
159
165
  },
160
- toggleProps: {
161
- variant: 'primary'
162
- }
166
+ toggleProps: toggleProps
163
167
  }, () => (0, _element.createElement)(_element.Fragment, null, isCreatingTemplate && (0, _element.createElement)(_templateActionsLoadingScreen.default, null), (0, _element.createElement)(_components.NavigableMenu, {
164
168
  className: "edit-site-new-template-dropdown__popover"
165
169
  }, (0, _element.createElement)(_components.MenuGroup, {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","home","single","post","page","archive","search","notFound","index","list","category","author","postAuthor","taxonomy","blockMeta","date","postDate","tag","attachment","media","NewTemplate","postType","showCustomTemplateModal","setShowCustomTemplateModal","showCustomGenericTemplateModal","setShowCustomGenericTemplateModal","entityForSuggestions","setEntityForSuggestions","isCreatingTemplate","setIsCreatingTemplate","history","saveEntityRecord","coreStore","createErrorNotice","createSuccessNotice","noticesStore","setTemplate","editSiteStore","createTemplate","template","isWPSuggestion","title","description","slug","templatePrefix","templateContent","content","fallbackTemplate","path","is_custom","template_prefix","raw","newTemplate","toString","status","is_wp_suggestion","throwOnError","id","push","postId","type","error","errorMessage","message","code","missingTemplates","useMissingTemplates","length","labels","add_new","add_new_item","noArrow","variant","map","onClick","icon","customGenericTemplateIcon","existingTemplates","defaultTemplateTypes","existingTemplateSlugs","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","enhancedMissingDefaultTemplateTypes","defaultTaxonomiesMenuItems","taxonomiesMenuItems","defaultPostTypesMenuItems","postTypesMenuItems","authorMenuItem","forEach","menuItem","matchIndex","findIndex","sort","template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CAACI,IAAT,KAAkBiD,QAAQ,CAACjD,IADzB,CAAnB,CAJ0B,CAO1B;AACA;AACA;AACA;AACA;;AACA,QAAKkD,UAAU,GAAG,CAAC,CAAnB,EAAuB;AACtBR,MAAAA,mCAAmC,CAAEQ,UAAF,CAAnC,GAAoDD,QAApD;AACA,KAFD,MAEO;AACNP,MAAAA,mCAAmC,CAAC3B,IAApC,CAA0CkC,QAA1C;AACA;AACD,GArBD,EA1BC,CAgDD;;AACAP,EAAAA,mCAAmC,SAAnC,IAAAA,mCAAmC,WAAnC,YAAAA,mCAAmC,CAAEU,IAArC,CAA2C,CAAEC,SAAF,EAAaC,SAAb,KAA4B;AACtE,WACClG,sBAAsB,CAACmG,OAAvB,CAAgCF,SAAS,CAACrD,IAA1C,IACA5C,sBAAsB,CAACmG,OAAvB,CAAgCD,SAAS,CAACtD,IAA1C,CAFD;AAIA,GALD;AAMA,QAAMsB,gBAAgB,GAAG,CACxB,GAAGoB,mCADqB,EAExB,GAAG,yCAFqB,EAGxB,GAAGI,kBAHqB,EAIxB,GAAGF,mBAJqB,CAAzB;AAMA,SAAOtB,gBAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tNavigableMenu,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tarchive,\n\tblockMeta,\n\tcategory,\n\thome,\n\tlist,\n\tmedia,\n\tnotFound,\n\tpage,\n\tpost,\n\tpostAuthor,\n\tpostDate,\n\tsearch,\n\ttag,\n\tlayout as customGenericTemplateIcon,\n} from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport AddCustomTemplateModal from './add-custom-template-modal';\nimport {\n\tuseExistingTemplates,\n\tuseDefaultTemplateTypes,\n\tuseTaxonomiesMenuItems,\n\tusePostTypeMenuItems,\n\tuseAuthorMenuItem,\n\tusePostTypeArchiveMenuItems,\n} from './utils';\nimport AddCustomGenericTemplateModal from './add-custom-generic-template-modal';\nimport TemplateActionsLoadingScreen from './template-actions-loading-screen';\nimport { useHistory } from '../routes';\nimport { store as editSiteStore } from '../../store';\n\nconst DEFAULT_TEMPLATE_SLUGS = [\n\t'front-page',\n\t'single',\n\t'page',\n\t'index',\n\t'archive',\n\t'author',\n\t'category',\n\t'date',\n\t'tag',\n\t'taxonomy',\n\t'search',\n\t'404',\n];\n\nconst TEMPLATE_ICONS = {\n\t'front-page': home,\n\tsingle: post,\n\tpage,\n\tarchive,\n\tsearch,\n\t404: notFound,\n\tindex: list,\n\tcategory,\n\tauthor: postAuthor,\n\ttaxonomy: blockMeta,\n\tdate: postDate,\n\ttag,\n\tattachment: media,\n};\n\nexport default function NewTemplate( { postType } ) {\n\tconst [ showCustomTemplateModal, setShowCustomTemplateModal ] =\n\t\tuseState( false );\n\tconst [\n\t\tshowCustomGenericTemplateModal,\n\t\tsetShowCustomGenericTemplateModal,\n\t] = useState( false );\n\tconst [ entityForSuggestions, setEntityForSuggestions ] = useState( {} );\n\tconst [ isCreatingTemplate, setIsCreatingTemplate ] = useState( false );\n\n\tconst history = useHistory();\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst { setTemplate } = useDispatch( editSiteStore );\n\n\tasync function createTemplate( template, isWPSuggestion = true ) {\n\t\tif ( isCreatingTemplate ) {\n\t\t\treturn;\n\t\t}\n\t\tsetIsCreatingTemplate( true );\n\t\ttry {\n\t\t\tconst { title, description, slug, templatePrefix } = template;\n\t\t\tlet templateContent = template.content;\n\t\t\t// Try to find fallback content from existing templates.\n\t\t\tif ( ! templateContent ) {\n\t\t\t\tconst fallbackTemplate = await apiFetch( {\n\t\t\t\t\tpath: addQueryArgs( '/wp/v2/templates/lookup', {\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tis_custom: ! isWPSuggestion,\n\t\t\t\t\t\ttemplate_prefix: templatePrefix,\n\t\t\t\t\t} ),\n\t\t\t\t} );\n\t\t\t\ttemplateContent = fallbackTemplate.content.raw;\n\t\t\t}\n\t\t\tconst newTemplate = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tdescription,\n\t\t\t\t\t// Slugs need to be strings, so this is for template `404`\n\t\t\t\t\tslug: slug.toString(),\n\t\t\t\t\tstatus: 'publish',\n\t\t\t\t\ttitle,\n\t\t\t\t\tcontent: templateContent,\n\t\t\t\t\t// This adds a post meta field in template that is part of `is_custom` value calculation.\n\t\t\t\t\tis_wp_suggestion: isWPSuggestion,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\t// Set template before navigating away to avoid initial stale value.\n\t\t\tsetTemplate( newTemplate.id, newTemplate.slug );\n\n\t\t\t// Navigate to the created template editor.\n\t\t\thistory.push( {\n\t\t\t\tpostId: newTemplate.id,\n\t\t\t\tpostType: newTemplate.type,\n\t\t\t} );\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: Title of the created template e.g: \"Category\".\n\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\ttitle\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while creating the template.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t} finally {\n\t\t\tsetIsCreatingTemplate( false );\n\t\t}\n\t}\n\n\tconst missingTemplates = useMissingTemplates(\n\t\tsetEntityForSuggestions,\n\t\tsetShowCustomTemplateModal\n\t);\n\tif ( ! missingTemplates.length ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<>\n\t\t\t<DropdownMenu\n\t\t\t\tclassName=\"edit-site-new-template-dropdown\"\n\t\t\t\ticon={ null }\n\t\t\t\ttext={ postType.labels.add_new }\n\t\t\t\tlabel={ postType.labels.add_new_item }\n\t\t\t\tpopoverProps={ {\n\t\t\t\t\tnoArrow: false,\n\t\t\t\t} }\n\t\t\t\ttoggleProps={ {\n\t\t\t\t\tvariant: 'primary',\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ () => (\n\t\t\t\t\t<>\n\t\t\t\t\t\t{ isCreatingTemplate && (\n\t\t\t\t\t\t\t<TemplateActionsLoadingScreen />\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<NavigableMenu className=\"edit-site-new-template-dropdown__popover\">\n\t\t\t\t\t\t\t<MenuGroup label={ postType.labels.add_new_item }>\n\t\t\t\t\t\t\t\t{ missingTemplates.map( ( template ) => {\n\t\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t\t\t\tonClick,\n\t\t\t\t\t\t\t\t\t\ticon,\n\t\t\t\t\t\t\t\t\t} = template;\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\t\t\t\ticon ||\n\t\t\t\t\t\t\t\t\t\t\t\tTEMPLATE_ICONS[ slug ] ||\n\t\t\t\t\t\t\t\t\t\t\t\tpost\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\t\t\tinfo={ description }\n\t\t\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t\t\tonClick\n\t\t\t\t\t\t\t\t\t\t\t\t\t? onClick( template )\n\t\t\t\t\t\t\t\t\t\t\t\t\t: createTemplate( template )\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ title }\n\t\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\ticon={ customGenericTemplateIcon }\n\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\tinfo={ __(\n\t\t\t\t\t\t\t\t\t\t'Custom templates can be applied to any post or page.'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\tkey=\"custom-template\"\n\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\tsetShowCustomGenericTemplateModal(\n\t\t\t\t\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Custom template' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t</NavigableMenu>\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t\t{ showCustomTemplateModal && (\n\t\t\t\t<AddCustomTemplateModal\n\t\t\t\t\tonClose={ () => setShowCustomTemplateModal( false ) }\n\t\t\t\t\tonSelect={ createTemplate }\n\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\tisCreatingTemplate={ isCreatingTemplate }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showCustomGenericTemplateModal && (\n\t\t\t\t<AddCustomGenericTemplateModal\n\t\t\t\t\tonClose={ () => setShowCustomGenericTemplateModal( false ) }\n\t\t\t\t\tcreateTemplate={ createTemplate }\n\t\t\t\t\tisCreatingTemplate={ isCreatingTemplate }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction useMissingTemplates(\n\tsetEntityForSuggestions,\n\tsetShowCustomTemplateModal\n) {\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst missingDefaultTemplates = ( defaultTemplateTypes || [] ).filter(\n\t\t( template ) =>\n\t\t\tDEFAULT_TEMPLATE_SLUGS.includes( template.slug ) &&\n\t\t\t! existingTemplateSlugs.includes( template.slug )\n\t);\n\tconst onClickMenuItem = ( _entityForSuggestions ) => {\n\t\tsetShowCustomTemplateModal( true );\n\t\tsetEntityForSuggestions( _entityForSuggestions );\n\t};\n\t// We need to replace existing default template types with\n\t// the create specific template functionality. The original\n\t// info (title, description, etc.) is preserved in the\n\t// used hooks.\n\tconst enhancedMissingDefaultTemplateTypes = [ ...missingDefaultTemplates ];\n\tconst { defaultTaxonomiesMenuItems, taxonomiesMenuItems } =\n\t\tuseTaxonomiesMenuItems( onClickMenuItem );\n\tconst { defaultPostTypesMenuItems, postTypesMenuItems } =\n\t\tusePostTypeMenuItems( onClickMenuItem );\n\n\tconst authorMenuItem = useAuthorMenuItem( onClickMenuItem );\n\t[\n\t\t...defaultTaxonomiesMenuItems,\n\t\t...defaultPostTypesMenuItems,\n\t\tauthorMenuItem,\n\t].forEach( ( menuItem ) => {\n\t\tif ( ! menuItem ) {\n\t\t\treturn;\n\t\t}\n\t\tconst matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(\n\t\t\t( template ) => template.slug === menuItem.slug\n\t\t);\n\t\t// Some default template types might have been filtered above from\n\t\t// `missingDefaultTemplates` because they only check for the general\n\t\t// template. So here we either replace or append the item, augmented\n\t\t// with the check if it has available specific item to create a\n\t\t// template for.\n\t\tif ( matchIndex > -1 ) {\n\t\t\tenhancedMissingDefaultTemplateTypes[ matchIndex ] = menuItem;\n\t\t} else {\n\t\t\tenhancedMissingDefaultTemplateTypes.push( menuItem );\n\t\t}\n\t} );\n\t// Update the sort order to match the DEFAULT_TEMPLATE_SLUGS order.\n\tenhancedMissingDefaultTemplateTypes?.sort( ( template1, template2 ) => {\n\t\treturn (\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template1.slug ) -\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template2.slug )\n\t\t);\n\t} );\n\tconst missingTemplates = [\n\t\t...enhancedMissingDefaultTemplateTypes,\n\t\t...usePostTypeArchiveMenuItems(),\n\t\t...postTypesMenuItems,\n\t\t...taxonomiesMenuItems,\n\t];\n\treturn missingTemplates;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","home","single","post","page","archive","search","notFound","index","list","category","author","postAuthor","taxonomy","blockMeta","date","postDate","tag","attachment","media","NewTemplate","postType","toggleProps","showIcon","showCustomTemplateModal","setShowCustomTemplateModal","showCustomGenericTemplateModal","setShowCustomGenericTemplateModal","entityForSuggestions","setEntityForSuggestions","isCreatingTemplate","setIsCreatingTemplate","history","saveEntityRecord","coreStore","createErrorNotice","createSuccessNotice","noticesStore","setTemplate","__unstableSetCanvasMode","editSiteStore","createTemplate","template","isWPSuggestion","title","description","slug","templatePrefix","templateContent","content","fallbackTemplate","path","is_custom","template_prefix","raw","newTemplate","toString","status","is_wp_suggestion","throwOnError","id","push","postId","type","error","errorMessage","message","code","missingTemplates","useMissingTemplates","length","plus","labels","add_new","add_new_item","noArrow","map","onClick","icon","customGenericTemplateIcon","existingTemplates","defaultTemplateTypes","existingTemplateSlugs","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","enhancedMissingDefaultTemplateTypes","defaultTaxonomiesMenuItems","taxonomiesMenuItems","defaultPostTypesMenuItems","postTypesMenuItems","authorMenuItem","forEach","menuItem","matchIndex","findIndex","sort","template1","template2","indexOf"],"mappings":";;;;;;;;;AAWA;;AARA;;AACA;;AACA;;AAOA;;AACA;;AACA;;AAiBA;;AACA;;AAKA;;AACA;;AAQA;;AACA;;AACA;;AACA;;AAjDA;AACA;AACA;;AAgCA;AACA;AACA;AAeA,MAAMA,sBAAsB,GAAG,CAC9B,YAD8B,EAE9B,QAF8B,EAG9B,MAH8B,EAI9B,OAJ8B,EAK9B,SAL8B,EAM9B,QAN8B,EAO9B,UAP8B,EAQ9B,MAR8B,EAS9B,KAT8B,EAU9B,UAV8B,EAW9B,QAX8B,EAY9B,KAZ8B,CAA/B;AAeA,MAAMC,cAAc,GAAG;AACtB,gBAAcC,WADQ;AAEtBC,EAAAA,MAAM,EAAEC,WAFc;AAGtBC,EAAAA,IAAI,EAAJA,WAHsB;AAItBC,EAAAA,OAAO,EAAPA,cAJsB;AAKtBC,EAAAA,MAAM,EAANA,aALsB;AAMtB,OAAKC,eANiB;AAOtBC,EAAAA,KAAK,EAAEC,WAPe;AAQtBC,EAAAA,QAAQ,EAARA,eARsB;AAStBC,EAAAA,MAAM,EAAEC,iBATc;AAUtBC,EAAAA,QAAQ,EAAEC,gBAVY;AAWtBC,EAAAA,IAAI,EAAEC,eAXgB;AAYtBC,EAAAA,GAAG,EAAHA,UAZsB;AAatBC,EAAAA,UAAU,EAAEC;AAbU,CAAvB;;AAgBe,SAASC,WAAT,OAIX;AAAA,MAJiC;AACpCC,IAAAA,QADoC;AAEpCC,IAAAA,WAFoC;AAGpCC,IAAAA,QAAQ,GAAG;AAHyB,GAIjC;AACH,QAAM,CAAEC,uBAAF,EAA2BC,0BAA3B,IACL,uBAAU,KAAV,CADD;AAEA,QA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xB,CADD;AAEA,QAAM;AAAEK,IAAAA,yBAAF;AAA6BC,IAAAA;AAA7B,MACL,iCAAsBN,eAAtB,CADD;AAGA,QAAMO,cAAc,GAAG,8BAAmBP,eAAnB,CAAvB;AACA,GACC,GAAGG,0BADJ,EAEC,GAAGE,yBAFJ,EAGCE,cAHD,EAIEC,OAJF,CAIaC,QAAF,IAAgB;AAC1B,QAAK,CAAEA,QAAP,EAAkB;AACjB;AACA;;AACD,UAAMC,UAAU,GAAGR,mCAAmC,CAACS,SAApC,CAChBvD,QAAF,IAAgBA,QAAQ,CAACI,IAAT,KAAkBiD,QAAQ,CAACjD,IADzB,CAAnB,CAJ0B,CAO1B;AACA;AACA;AACA;AACA;;AACA,QAAKkD,UAAU,GAAG,CAAC,CAAnB,EAAuB;AACtBR,MAAAA,mCAAmC,CAAEQ,UAAF,CAAnC,GAAoDD,QAApD;AACA,KAFD,MAEO;AACNP,MAAAA,mCAAmC,CAAC3B,IAApC,CAA0CkC,QAA1C;AACA;AACD,GArBD,EA1BC,CAgDD;;AACAP,EAAAA,mCAAmC,SAAnC,IAAAA,mCAAmC,WAAnC,YAAAA,mCAAmC,CAAEU,IAArC,CAA2C,CAAEC,SAAF,EAAaC,SAAb,KAA4B;AACtE,WACCrG,sBAAsB,CAACsG,OAAvB,CAAgCF,SAAS,CAACrD,IAA1C,IACA/C,sBAAsB,CAACsG,OAAvB,CAAgCD,SAAS,CAACtD,IAA1C,CAFD;AAIA,GALD;AAMA,QAAMsB,gBAAgB,GAAG,CACxB,GAAGoB,mCADqB,EAExB,GAAG,yCAFqB,EAGxB,GAAGI,kBAHqB,EAIxB,GAAGF,mBAJqB,CAAzB;AAMA,SAAOtB,gBAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tNavigableMenu,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tarchive,\n\tblockMeta,\n\tcategory,\n\thome,\n\tlist,\n\tmedia,\n\tnotFound,\n\tpage,\n\tplus,\n\tpost,\n\tpostAuthor,\n\tpostDate,\n\tsearch,\n\ttag,\n\tlayout as customGenericTemplateIcon,\n} from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport AddCustomTemplateModal from './add-custom-template-modal';\nimport {\n\tuseExistingTemplates,\n\tuseDefaultTemplateTypes,\n\tuseTaxonomiesMenuItems,\n\tusePostTypeMenuItems,\n\tuseAuthorMenuItem,\n\tusePostTypeArchiveMenuItems,\n} from './utils';\nimport AddCustomGenericTemplateModal from './add-custom-generic-template-modal';\nimport TemplateActionsLoadingScreen from './template-actions-loading-screen';\nimport { useHistory } from '../routes';\nimport { store as editSiteStore } from '../../store';\n\nconst DEFAULT_TEMPLATE_SLUGS = [\n\t'front-page',\n\t'single',\n\t'page',\n\t'index',\n\t'archive',\n\t'author',\n\t'category',\n\t'date',\n\t'tag',\n\t'taxonomy',\n\t'search',\n\t'404',\n];\n\nconst TEMPLATE_ICONS = {\n\t'front-page': home,\n\tsingle: post,\n\tpage,\n\tarchive,\n\tsearch,\n\t404: notFound,\n\tindex: list,\n\tcategory,\n\tauthor: postAuthor,\n\ttaxonomy: blockMeta,\n\tdate: postDate,\n\ttag,\n\tattachment: media,\n};\n\nexport default function NewTemplate( {\n\tpostType,\n\ttoggleProps,\n\tshowIcon = true,\n} ) {\n\tconst [ showCustomTemplateModal, setShowCustomTemplateModal ] =\n\t\tuseState( false );\n\tconst [\n\t\tshowCustomGenericTemplateModal,\n\t\tsetShowCustomGenericTemplateModal,\n\t] = useState( false );\n\tconst [ entityForSuggestions, setEntityForSuggestions ] = useState( {} );\n\tconst [ isCreatingTemplate, setIsCreatingTemplate ] = useState( false );\n\n\tconst history = useHistory();\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst { setTemplate, __unstableSetCanvasMode } =\n\t\tuseDispatch( editSiteStore );\n\n\tasync function createTemplate( template, isWPSuggestion = true ) {\n\t\tif ( isCreatingTemplate ) {\n\t\t\treturn;\n\t\t}\n\t\tsetIsCreatingTemplate( true );\n\t\ttry {\n\t\t\tconst { title, description, slug, templatePrefix } = template;\n\t\t\tlet templateContent = template.content;\n\t\t\t// Try to find fallback content from existing templates.\n\t\t\tif ( ! templateContent ) {\n\t\t\t\tconst fallbackTemplate = await apiFetch( {\n\t\t\t\t\tpath: addQueryArgs( '/wp/v2/templates/lookup', {\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tis_custom: ! isWPSuggestion,\n\t\t\t\t\t\ttemplate_prefix: templatePrefix,\n\t\t\t\t\t} ),\n\t\t\t\t} );\n\t\t\t\ttemplateContent = fallbackTemplate.content.raw;\n\t\t\t}\n\t\t\tconst newTemplate = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tdescription,\n\t\t\t\t\t// Slugs need to be strings, so this is for template `404`\n\t\t\t\t\tslug: slug.toString(),\n\t\t\t\t\tstatus: 'publish',\n\t\t\t\t\ttitle,\n\t\t\t\t\tcontent: templateContent,\n\t\t\t\t\t// This adds a post meta field in template that is part of `is_custom` value calculation.\n\t\t\t\t\tis_wp_suggestion: isWPSuggestion,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\t// Set template before navigating away to avoid initial stale value.\n\t\t\tsetTemplate( newTemplate.id, newTemplate.slug );\n\n\t\t\t// Switch to edit mode.\n\t\t\t__unstableSetCanvasMode( 'edit' );\n\n\t\t\t// Navigate to the created template editor.\n\t\t\thistory.push( {\n\t\t\t\tpostId: newTemplate.id,\n\t\t\t\tpostType: newTemplate.type,\n\t\t\t} );\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: Title of the created template e.g: \"Category\".\n\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\ttitle\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while creating the template.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t} finally {\n\t\t\tsetIsCreatingTemplate( false );\n\t\t}\n\t}\n\n\tconst missingTemplates = useMissingTemplates(\n\t\tsetEntityForSuggestions,\n\t\tsetShowCustomTemplateModal\n\t);\n\tif ( ! missingTemplates.length ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<>\n\t\t\t<DropdownMenu\n\t\t\t\tclassName=\"edit-site-new-template-dropdown\"\n\t\t\t\ticon={ showIcon ? plus : null }\n\t\t\t\ttext={ showIcon ? null : postType.labels.add_new }\n\t\t\t\tlabel={ postType.labels.add_new_item }\n\t\t\t\tpopoverProps={ {\n\t\t\t\t\tnoArrow: false,\n\t\t\t\t} }\n\t\t\t\ttoggleProps={ toggleProps }\n\t\t\t>\n\t\t\t\t{ () => (\n\t\t\t\t\t<>\n\t\t\t\t\t\t{ isCreatingTemplate && (\n\t\t\t\t\t\t\t<TemplateActionsLoadingScreen />\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<NavigableMenu className=\"edit-site-new-template-dropdown__popover\">\n\t\t\t\t\t\t\t<MenuGroup label={ postType.labels.add_new_item }>\n\t\t\t\t\t\t\t\t{ missingTemplates.map( ( template ) => {\n\t\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t\t\t\tonClick,\n\t\t\t\t\t\t\t\t\t\ticon,\n\t\t\t\t\t\t\t\t\t} = template;\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\t\t\t\ticon ||\n\t\t\t\t\t\t\t\t\t\t\t\tTEMPLATE_ICONS[ slug ] ||\n\t\t\t\t\t\t\t\t\t\t\t\tpost\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\t\t\tinfo={ description }\n\t\t\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t\t\tonClick\n\t\t\t\t\t\t\t\t\t\t\t\t\t? onClick( template )\n\t\t\t\t\t\t\t\t\t\t\t\t\t: createTemplate( template )\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ title }\n\t\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\ticon={ customGenericTemplateIcon }\n\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\tinfo={ __(\n\t\t\t\t\t\t\t\t\t\t'Custom templates can be applied to any post or page.'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\tkey=\"custom-template\"\n\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\tsetShowCustomGenericTemplateModal(\n\t\t\t\t\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Custom template' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t</NavigableMenu>\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t\t{ showCustomTemplateModal && (\n\t\t\t\t<AddCustomTemplateModal\n\t\t\t\t\tonClose={ () => setShowCustomTemplateModal( false ) }\n\t\t\t\t\tonSelect={ createTemplate }\n\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\tisCreatingTemplate={ isCreatingTemplate }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showCustomGenericTemplateModal && (\n\t\t\t\t<AddCustomGenericTemplateModal\n\t\t\t\t\tonClose={ () => setShowCustomGenericTemplateModal( false ) }\n\t\t\t\t\tcreateTemplate={ createTemplate }\n\t\t\t\t\tisCreatingTemplate={ isCreatingTemplate }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction useMissingTemplates(\n\tsetEntityForSuggestions,\n\tsetShowCustomTemplateModal\n) {\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst missingDefaultTemplates = ( defaultTemplateTypes || [] ).filter(\n\t\t( template ) =>\n\t\t\tDEFAULT_TEMPLATE_SLUGS.includes( template.slug ) &&\n\t\t\t! existingTemplateSlugs.includes( template.slug )\n\t);\n\tconst onClickMenuItem = ( _entityForSuggestions ) => {\n\t\tsetShowCustomTemplateModal( true );\n\t\tsetEntityForSuggestions( _entityForSuggestions );\n\t};\n\t// We need to replace existing default template types with\n\t// the create specific template functionality. The original\n\t// info (title, description, etc.) is preserved in the\n\t// used hooks.\n\tconst enhancedMissingDefaultTemplateTypes = [ ...missingDefaultTemplates ];\n\tconst { defaultTaxonomiesMenuItems, taxonomiesMenuItems } =\n\t\tuseTaxonomiesMenuItems( onClickMenuItem );\n\tconst { defaultPostTypesMenuItems, postTypesMenuItems } =\n\t\tusePostTypeMenuItems( onClickMenuItem );\n\n\tconst authorMenuItem = useAuthorMenuItem( onClickMenuItem );\n\t[\n\t\t...defaultTaxonomiesMenuItems,\n\t\t...defaultPostTypesMenuItems,\n\t\tauthorMenuItem,\n\t].forEach( ( menuItem ) => {\n\t\tif ( ! menuItem ) {\n\t\t\treturn;\n\t\t}\n\t\tconst matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(\n\t\t\t( template ) => template.slug === menuItem.slug\n\t\t);\n\t\t// Some default template types might have been filtered above from\n\t\t// `missingDefaultTemplates` because they only check for the general\n\t\t// template. So here we either replace or append the item, augmented\n\t\t// with the check if it has available specific item to create a\n\t\t// template for.\n\t\tif ( matchIndex > -1 ) {\n\t\t\tenhancedMissingDefaultTemplateTypes[ matchIndex ] = menuItem;\n\t\t} else {\n\t\t\tenhancedMissingDefaultTemplateTypes.push( menuItem );\n\t\t}\n\t} );\n\t// Update the sort order to match the DEFAULT_TEMPLATE_SLUGS order.\n\tenhancedMissingDefaultTemplateTypes?.sort( ( template1, template2 ) => {\n\t\treturn (\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template1.slug ) -\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template2.slug )\n\t\t);\n\t} );\n\tconst missingTemplates = [\n\t\t...enhancedMissingDefaultTemplateTypes,\n\t\t...usePostTypeArchiveMenuItems(),\n\t\t...postTypesMenuItems,\n\t\t...taxonomiesMenuItems,\n\t];\n\treturn missingTemplates;\n}\n"]}
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = EditSiteApp;
8
+ exports.default = App;
9
9
 
10
10
  var _element = require("@wordpress/element");
11
11
 
@@ -13,6 +13,8 @@ var _components = require("@wordpress/components");
13
13
 
14
14
  var _editor = require("@wordpress/editor");
15
15
 
16
+ var _keyboardShortcuts = require("@wordpress/keyboard-shortcuts");
17
+
16
18
  var _notices = require("@wordpress/notices");
17
19
 
18
20
  var _data = require("@wordpress/data");
@@ -23,13 +25,7 @@ var _plugins = require("@wordpress/plugins");
23
25
 
24
26
  var _routes = require("../routes");
25
27
 
26
- var _editor2 = _interopRequireDefault(require("../editor"));
27
-
28
- var _list = _interopRequireDefault(require("../list"));
29
-
30
- var _navigationSidebar = _interopRequireDefault(require("../navigation-sidebar"));
31
-
32
- var _getIsListPage = _interopRequireDefault(require("../../utils/get-is-list-page"));
28
+ var _layout = _interopRequireDefault(require("../layout"));
33
29
 
34
30
  /**
35
31
  * WordPress dependencies
@@ -38,10 +34,9 @@ var _getIsListPage = _interopRequireDefault(require("../../utils/get-is-list-pag
38
34
  /**
39
35
  * Internal dependencies
40
36
  */
41
- function EditSiteApp(_ref) {
37
+ function App(_ref) {
42
38
  let {
43
- reboot,
44
- homeTemplate
39
+ reboot
45
40
  } = _ref;
46
41
  const {
47
42
  createErrorNotice
@@ -53,24 +48,14 @@ function EditSiteApp(_ref) {
53
48
  (0, _i18n.__)('The "%s" plugin has encountered an error and cannot be rendered.'), name));
54
49
  }
55
50
 
56
- return (0, _element.createElement)(_components.SlotFillProvider, null, (0, _element.createElement)(_editor.UnsavedChangesWarning, null), (0, _element.createElement)(_routes.Routes, null, _ref2 => {
57
- var _params$postId;
58
-
59
- let {
60
- params
61
- } = _ref2;
62
- const isListPage = (0, _getIsListPage.default)(params); // The existence of a 'front-page' supersedes every other setting.
63
-
64
- const homeTemplateType = (_params$postId = params.postId) !== null && _params$postId !== void 0 && _params$postId.includes('front-page') || params.postId === (homeTemplate === null || homeTemplate === void 0 ? void 0 : homeTemplate.postId) ? 'site-editor' : undefined;
65
- return (0, _element.createElement)(_element.Fragment, null, isListPage ? (0, _element.createElement)(_list.default, null) : (0, _element.createElement)(_editor2.default, {
66
- onError: reboot
67
- }), (0, _element.createElement)(_plugins.PluginArea, {
68
- onError: onPluginAreaError
69
- }), (0, _element.createElement)(_navigationSidebar.default // Open the navigation sidebar by default when in the list page.
70
- , {
71
- isDefaultOpen: !!isListPage,
72
- activeTemplateType: isListPage ? params.postType : homeTemplateType
73
- }));
74
- }));
51
+ return (0, _element.createElement)(_keyboardShortcuts.ShortcutProvider, {
52
+ style: {
53
+ height: '100%'
54
+ }
55
+ }, (0, _element.createElement)(_components.SlotFillProvider, null, (0, _element.createElement)(_components.Popover.Slot, null), (0, _element.createElement)(_editor.UnsavedChangesWarning, null), (0, _element.createElement)(_routes.Routes, null, (0, _element.createElement)(_layout.default, {
56
+ onError: reboot
57
+ }), (0, _element.createElement)(_plugins.PluginArea, {
58
+ onError: onPluginAreaError
59
+ }))));
75
60
  }
76
61
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/app/index.js"],"names":["EditSiteApp","reboot","homeTemplate","createErrorNotice","noticesStore","onPluginAreaError","name","params","isListPage","homeTemplateType","postId","includes","undefined","postType"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAjBA;AACA;AACA;;AAQA;AACA;AACA;AAOe,SAASA,WAAT,OAAiD;AAAA,MAA3B;AAAEC,IAAAA,MAAF;AAAUC,IAAAA;AAAV,GAA2B;AAC/D,QAAM;AAAEC,IAAAA;AAAF,MAAwB,uBAAaC,cAAb,CAA9B;;AAEA,WAASC,iBAAT,CAA4BC,IAA5B,EAAmC;AAClCH,IAAAA,iBAAiB,CAChB;AACC;AACA,kBACC,kEADD,CAFD,EAKCG,IALD,CADgB,CAAjB;AASA;;AAED,SACC,4BAAC,4BAAD,QACC,4BAAC,6BAAD,OADD,EAGC,4BAAC,cAAD,QACG,SAAkB;AAAA;;AAAA,QAAhB;AAAEC,MAAAA;AAAF,KAAgB;AACnB,UAAMC,UAAU,GAAG,4BAAeD,MAAf,CAAnB,CADmB,CAGnB;;AACA,UAAME,gBAAgB,GACrB,kBAAAF,MAAM,CAACG,MAAP,0DAAeC,QAAf,CAAyB,YAAzB,KACAJ,MAAM,CAACG,MAAP,MAAkBR,YAAlB,aAAkBA,YAAlB,uBAAkBA,YAAY,CAAEQ,MAAhC,CADA,GAEG,aAFH,GAGGE,SAJJ;AAMA,WACC,qDACGJ,UAAU,GACX,4BAAC,aAAD,OADW,GAGX,4BAAC,gBAAD;AAAQ,MAAA,OAAO,EAAGP;AAAlB,MAJF,EAMC,4BAAC,mBAAD;AAAY,MAAA,OAAO,EAAGI;AAAtB,MAND,EASC,4BAAC,0BAAD,CACC;AADD;AAEC,MAAA,aAAa,EAAG,CAAC,CAAEG,UAFpB;AAGC,MAAA,kBAAkB,EACjBA,UAAU,GACPD,MAAM,CAACM,QADA,GAEPJ;AANL,MATD,CADD;AAqBA,GAhCF,CAHD,CADD;AAwCA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { SlotFillProvider } from '@wordpress/components';\nimport { UnsavedChangesWarning } from '@wordpress/editor';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useDispatch } from '@wordpress/data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { PluginArea } from '@wordpress/plugins';\n\n/**\n * Internal dependencies\n */\nimport { Routes } from '../routes';\nimport Editor from '../editor';\nimport List from '../list';\nimport NavigationSidebar from '../navigation-sidebar';\nimport getIsListPage from '../../utils/get-is-list-page';\n\nexport default function EditSiteApp( { reboot, homeTemplate } ) {\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tfunction onPluginAreaError( name ) {\n\t\tcreateErrorNotice(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %s: plugin name */\n\t\t\t\t__(\n\t\t\t\t\t'The \"%s\" plugin has encountered an error and cannot be rendered.'\n\t\t\t\t),\n\t\t\t\tname\n\t\t\t)\n\t\t);\n\t}\n\n\treturn (\n\t\t<SlotFillProvider>\n\t\t\t<UnsavedChangesWarning />\n\n\t\t\t<Routes>\n\t\t\t\t{ ( { params } ) => {\n\t\t\t\t\tconst isListPage = getIsListPage( params );\n\n\t\t\t\t\t// The existence of a 'front-page' supersedes every other setting.\n\t\t\t\t\tconst homeTemplateType =\n\t\t\t\t\t\tparams.postId?.includes( 'front-page' ) ||\n\t\t\t\t\t\tparams.postId === homeTemplate?.postId\n\t\t\t\t\t\t\t? 'site-editor'\n\t\t\t\t\t\t\t: undefined;\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t{ isListPage ? (\n\t\t\t\t\t\t\t\t<List />\n\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t<Editor onError={ reboot } />\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t<PluginArea onError={ onPluginAreaError } />\n\t\t\t\t\t\t\t{ /* Keep the instance of the sidebar to ensure focus will not be lost\n\t\t\t\t\t\t\t * when navigating to other pages. */ }\n\t\t\t\t\t\t\t<NavigationSidebar\n\t\t\t\t\t\t\t\t// Open the navigation sidebar by default when in the list page.\n\t\t\t\t\t\t\t\tisDefaultOpen={ !! isListPage }\n\t\t\t\t\t\t\t\tactiveTemplateType={\n\t\t\t\t\t\t\t\t\tisListPage\n\t\t\t\t\t\t\t\t\t\t? params.postType\n\t\t\t\t\t\t\t\t\t\t: homeTemplateType\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</>\n\t\t\t\t\t);\n\t\t\t\t} }\n\t\t\t</Routes>\n\t\t</SlotFillProvider>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/app/index.js"],"names":["App","reboot","createErrorNotice","noticesStore","onPluginAreaError","name","height"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAfA;AACA;AACA;;AASA;AACA;AACA;AAIe,SAASA,GAAT,OAA2B;AAAA,MAAb;AAAEC,IAAAA;AAAF,GAAa;AACzC,QAAM;AAAEC,IAAAA;AAAF,MAAwB,uBAAaC,cAAb,CAA9B;;AAEA,WAASC,iBAAT,CAA4BC,IAA5B,EAAmC;AAClCH,IAAAA,iBAAiB,CAChB;AACC;AACA,kBACC,kEADD,CAFD,EAKCG,IALD,CADgB,CAAjB;AASA;;AAED,SACC,4BAAC,mCAAD;AAAkB,IAAA,KAAK,EAAG;AAAEC,MAAAA,MAAM,EAAE;AAAV;AAA1B,KACC,4BAAC,4BAAD,QACC,4BAAC,mBAAD,CAAS,IAAT,OADD,EAEC,4BAAC,6BAAD,OAFD,EAIC,4BAAC,cAAD,QACC,4BAAC,eAAD;AAAQ,IAAA,OAAO,EAAGL;AAAlB,IADD,EAEC,4BAAC,mBAAD;AAAY,IAAA,OAAO,EAAGG;AAAtB,IAFD,CAJD,CADD,CADD;AAaA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { SlotFillProvider, Popover } from '@wordpress/components';\nimport { UnsavedChangesWarning } from '@wordpress/editor';\nimport { ShortcutProvider } from '@wordpress/keyboard-shortcuts';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useDispatch } from '@wordpress/data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { PluginArea } from '@wordpress/plugins';\n\n/**\n * Internal dependencies\n */\nimport { Routes } from '../routes';\nimport Layout from '../layout';\n\nexport default function App( { reboot } ) {\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tfunction onPluginAreaError( name ) {\n\t\tcreateErrorNotice(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %s: plugin name */\n\t\t\t\t__(\n\t\t\t\t\t'The \"%s\" plugin has encountered an error and cannot be rendered.'\n\t\t\t\t),\n\t\t\t\tname\n\t\t\t)\n\t\t);\n\t}\n\n\treturn (\n\t\t<ShortcutProvider style={ { height: '100%' } }>\n\t\t\t<SlotFillProvider>\n\t\t\t\t<Popover.Slot />\n\t\t\t\t<UnsavedChangesWarning />\n\n\t\t\t\t<Routes>\n\t\t\t\t\t<Layout onError={ reboot } />\n\t\t\t\t\t<PluginArea onError={ onPluginAreaError } />\n\t\t\t\t</Routes>\n\t\t\t</SlotFillProvider>\n\t\t</ShortcutProvider>\n\t);\n}\n"]}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _element = require("@wordpress/element");
11
+
12
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
+
14
+ var _blockEditor = require("@wordpress/block-editor");
15
+
16
+ var _data = require("@wordpress/data");
17
+
18
+ var _store = require("../../store");
19
+
20
+ /**
21
+ * WordPress dependencies
22
+ */
23
+
24
+ /**
25
+ * Internal dependencies
26
+ */
27
+ function EditorCanvas(_ref) {
28
+ let {
29
+ enableResizing,
30
+ settings,
31
+ children,
32
+ ...props
33
+ } = _ref;
34
+ const {
35
+ deviceType,
36
+ isZoomOutMode
37
+ } = (0, _data.useSelect)(select => ({
38
+ deviceType: select(_store.store).__experimentalGetPreviewDeviceType(),
39
+ isZoomOutMode: select(_blockEditor.store).__unstableGetEditorMode() === 'zoom-out'
40
+ }), []);
41
+ const deviceStyles = (0, _blockEditor.__experimentalUseResizeCanvas)(deviceType);
42
+ const mouseMoveTypingRef = (0, _blockEditor.__unstableUseMouseMoveTypingReset)();
43
+ return (0, _element.createElement)(_blockEditor.__unstableIframe, (0, _extends2.default)({
44
+ scale: isZoomOutMode && 0.45 || undefined,
45
+ frameSize: isZoomOutMode ? 100 : undefined,
46
+ style: enableResizing ? {} : deviceStyles,
47
+ head: (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_blockEditor.__unstableEditorStyles, {
48
+ styles: settings.styles
49
+ }), (0, _element.createElement)("style", null, // Forming a "block formatting context" to prevent margin collapsing.
50
+ // @see https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context
51
+ `.is-root-container { display: flow-root; }
52
+ body { position: relative; }`), enableResizing && (0, _element.createElement)("style", null, // Some themes will have `min-height: 100vh` for the root container,
53
+ // which isn't a requirement in auto resize mode.
54
+ `.is-root-container { min-height: 0 !important; }`)),
55
+ assets: settings.__unstableResolvedAssets,
56
+ ref: mouseMoveTypingRef,
57
+ name: "editor-canvas",
58
+ className: "edit-site-visual-editor__editor-canvas"
59
+ }, props), settings.svgFilters, children);
60
+ }
61
+
62
+ var _default = EditorCanvas;
63
+ exports.default = _default;
64
+ //# sourceMappingURL=editor-canvas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/block-editor/editor-canvas.js"],"names":["EditorCanvas","enableResizing","settings","children","props","deviceType","isZoomOutMode","select","editSiteStore","__experimentalGetPreviewDeviceType","blockEditorStore","__unstableGetEditorMode","deviceStyles","mouseMoveTypingRef","undefined","styles","__unstableResolvedAssets","svgFilters"],"mappings":";;;;;;;;;;;;;AAGA;;AAOA;;AAKA;;AAfA;AACA;AACA;;AAUA;AACA;AACA;AAGA,SAASA,YAAT,OAA0E;AAAA,MAAnD;AAAEC,IAAAA,cAAF;AAAkBC,IAAAA,QAAlB;AAA4BC,IAAAA,QAA5B;AAAsC,OAAGC;AAAzC,GAAmD;AACzE,QAAM;AAAEC,IAAAA,UAAF;AAAcC,IAAAA;AAAd,MAAgC,qBACnCC,MAAF,KAAgB;AACfF,IAAAA,UAAU,EACTE,MAAM,CAAEC,YAAF,CAAN,CAAwBC,kCAAxB,EAFc;AAGfH,IAAAA,aAAa,EACZC,MAAM,CAAEG,kBAAF,CAAN,CAA2BC,uBAA3B,OACA;AALc,GAAhB,CADqC,EAQrC,EARqC,CAAtC;AAUA,QAAMC,YAAY,GAAG,gDAAiBP,UAAjB,CAArB;AACA,QAAMQ,kBAAkB,GAAG,qDAA3B;AACA,SACC,4BAAC,6BAAD;AACC,IAAA,KAAK,EAAKP,aAAa,IAAI,IAAnB,IAA6BQ,SADtC;AAEC,IAAA,SAAS,EAAGR,aAAa,GAAG,GAAH,GAASQ,SAFnC;AAGC,IAAA,KAAK,EAAGb,cAAc,GAAG,EAAH,GAAQW,YAH/B;AAIC,IAAA,IAAI,EACH,qDACC,4BAAC,mCAAD;AAAc,MAAA,MAAM,EAAGV,QAAQ,CAACa;AAAhC,MADD,EAEC,2CACC;AACA;AACC;AACP,oCAJK,CAFD,EAQGd,cAAc,IACf,2CAEE;AACA;AACC,sDAJH,CATF,CALF;AAwBC,IAAA,MAAM,EAAGC,QAAQ,CAACc,wBAxBnB;AAyBC,IAAA,GAAG,EAAGH,kBAzBP;AA0BC,IAAA,IAAI,EAAC,eA1BN;AA2BC,IAAA,SAAS,EAAC;AA3BX,KA4BMT,KA5BN,GA+BGF,QAAQ,CAACe,UA/BZ,EAgCGd,QAhCH,CADD;AAoCA;;eAEcH,Y","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalUseResizeCanvas as useResizeCanvas,\n\t__unstableEditorStyles as EditorStyles,\n\t__unstableIframe as Iframe,\n\t__unstableUseMouseMoveTypingReset as useMouseMoveTypingReset,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\n\nfunction EditorCanvas( { enableResizing, settings, children, ...props } ) {\n\tconst { deviceType, isZoomOutMode } = useSelect(\n\t\t( select ) => ( {\n\t\t\tdeviceType:\n\t\t\t\tselect( editSiteStore ).__experimentalGetPreviewDeviceType(),\n\t\t\tisZoomOutMode:\n\t\t\t\tselect( blockEditorStore ).__unstableGetEditorMode() ===\n\t\t\t\t'zoom-out',\n\t\t} ),\n\t\t[]\n\t);\n\tconst deviceStyles = useResizeCanvas( deviceType );\n\tconst mouseMoveTypingRef = useMouseMoveTypingReset();\n\treturn (\n\t\t<Iframe\n\t\t\tscale={ ( isZoomOutMode && 0.45 ) || undefined }\n\t\t\tframeSize={ isZoomOutMode ? 100 : undefined }\n\t\t\tstyle={ enableResizing ? {} : deviceStyles }\n\t\t\thead={\n\t\t\t\t<>\n\t\t\t\t\t<EditorStyles styles={ settings.styles } />\n\t\t\t\t\t<style>{\n\t\t\t\t\t\t// Forming a \"block formatting context\" to prevent margin collapsing.\n\t\t\t\t\t\t// @see https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context\n\t\t\t\t\t\t`.is-root-container { display: flow-root; }\n\t\t\t\t\t\t\tbody { position: relative; }`\n\t\t\t\t\t}</style>\n\t\t\t\t\t{ enableResizing && (\n\t\t\t\t\t\t<style>\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t// Some themes will have `min-height: 100vh` for the root container,\n\t\t\t\t\t\t\t\t// which isn't a requirement in auto resize mode.\n\t\t\t\t\t\t\t\t`.is-root-container { min-height: 0 !important; }`\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t</style>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t}\n\t\t\tassets={ settings.__unstableResolvedAssets }\n\t\t\tref={ mouseMoveTypingRef }\n\t\t\tname=\"editor-canvas\"\n\t\t\tclassName=\"edit-site-visual-editor__editor-canvas\"\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ /* Filters need to be rendered before children to avoid Safari rendering issues. */ }\n\t\t\t{ settings.svgFilters }\n\t\t\t{ children }\n\t\t</Iframe>\n\t);\n}\n\nexport default EditorCanvas;\n"]}