@wordpress/edit-site 4.10.0 → 4.12.1-next.d6164808d3.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 (204) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/components/add-new-template/add-custom-template-modal.js +26 -44
  3. package/build/components/add-new-template/add-custom-template-modal.js.map +1 -1
  4. package/build/components/add-new-template/new-template.js +45 -23
  5. package/build/components/add-new-template/new-template.js.map +1 -1
  6. package/build/components/add-new-template/utils.js +493 -242
  7. package/build/components/add-new-template/utils.js.map +1 -1
  8. package/build/components/block-editor/index.js +1 -3
  9. package/build/components/block-editor/index.js.map +1 -1
  10. package/build/components/block-editor/resizable-editor.js +26 -12
  11. package/build/components/block-editor/resizable-editor.js.map +1 -1
  12. package/build/components/global-styles/border-panel.js +3 -3
  13. package/build/components/global-styles/border-panel.js.map +1 -1
  14. package/build/components/global-styles/dimensions-panel.js +280 -20
  15. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  16. package/build/components/global-styles/hooks.js +4 -4
  17. package/build/components/global-styles/hooks.js.map +1 -1
  18. package/build/components/global-styles/screen-color-palette.js +1 -1
  19. package/build/components/global-styles/screen-color-palette.js.map +1 -1
  20. package/build/components/global-styles/screen-colors.js +51 -7
  21. package/build/components/global-styles/screen-colors.js.map +1 -1
  22. package/build/components/global-styles/screen-heading-color.js +157 -0
  23. package/build/components/global-styles/screen-heading-color.js.map +1 -0
  24. package/build/components/global-styles/screen-typography-element.js +4 -0
  25. package/build/components/global-styles/screen-typography-element.js.map +1 -1
  26. package/build/components/global-styles/screen-typography.js +5 -0
  27. package/build/components/global-styles/screen-typography.js.map +1 -1
  28. package/build/components/global-styles/typography-panel.js +82 -14
  29. package/build/components/global-styles/typography-panel.js.map +1 -1
  30. package/build/components/global-styles/typography-utils.js +217 -0
  31. package/build/components/global-styles/typography-utils.js.map +1 -0
  32. package/build/components/global-styles/ui.js +11 -0
  33. package/build/components/global-styles/ui.js.map +1 -1
  34. package/build/components/global-styles/use-global-styles-output.js +183 -52
  35. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  36. package/build/components/global-styles/utils.js +85 -5
  37. package/build/components/global-styles/utils.js.map +1 -1
  38. package/build/components/header/document-actions/index.js +1 -0
  39. package/build/components/header/document-actions/index.js.map +1 -1
  40. package/build/components/header/index.js +27 -12
  41. package/build/components/header/index.js.map +1 -1
  42. package/build/components/header/mode-switcher/index.js +0 -4
  43. package/build/components/header/mode-switcher/index.js.map +1 -1
  44. package/build/components/header/more-menu/index.js +13 -3
  45. package/build/components/header/more-menu/index.js.map +1 -1
  46. package/build/components/header/undo-redo/redo.js +2 -1
  47. package/build/components/header/undo-redo/redo.js.map +1 -1
  48. package/build/components/list/actions/index.js +1 -1
  49. package/build/components/list/actions/index.js.map +1 -1
  50. package/build/components/save-button/index.js +2 -3
  51. package/build/components/save-button/index.js.map +1 -1
  52. package/build/components/sidebar/default-sidebar.js +11 -1
  53. package/build/components/sidebar/default-sidebar.js.map +1 -1
  54. package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js +2 -2
  55. package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
  56. package/build/components/sidebar/plugin-sidebar/index.js +11 -1
  57. package/build/components/sidebar/plugin-sidebar/index.js.map +1 -1
  58. package/build/components/sidebar/template-card/template-actions.js +1 -1
  59. package/build/components/sidebar/template-card/template-actions.js.map +1 -1
  60. package/build/components/template-details/edit-template-title.js +1 -1
  61. package/build/components/template-details/edit-template-title.js.map +1 -1
  62. package/build/components/template-details/index.js +19 -9
  63. package/build/components/template-details/index.js.map +1 -1
  64. package/build/components/template-details/template-areas.js +1 -1
  65. package/build/components/template-details/template-areas.js.map +1 -1
  66. package/build/components/template-details/template-part-area-selector.js +47 -0
  67. package/build/components/template-details/template-part-area-selector.js.map +1 -0
  68. package/build/components/template-part-converter/convert-to-template-part.js +4 -1
  69. package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
  70. package/build/hooks/index.js +2 -0
  71. package/build/hooks/index.js.map +1 -1
  72. package/build/hooks/template-part-edit.js +86 -0
  73. package/build/hooks/template-part-edit.js.map +1 -0
  74. package/build/index.js +1 -1
  75. package/build/index.js.map +1 -1
  76. package/build-module/components/add-new-template/add-custom-template-modal.js +27 -45
  77. package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -1
  78. package/build-module/components/add-new-template/new-template.js +45 -25
  79. package/build-module/components/add-new-template/new-template.js.map +1 -1
  80. package/build-module/components/add-new-template/utils.js +489 -230
  81. package/build-module/components/add-new-template/utils.js.map +1 -1
  82. package/build-module/components/block-editor/index.js +1 -2
  83. package/build-module/components/block-editor/index.js.map +1 -1
  84. package/build-module/components/block-editor/resizable-editor.js +26 -12
  85. package/build-module/components/block-editor/resizable-editor.js.map +1 -1
  86. package/build-module/components/global-styles/border-panel.js +3 -3
  87. package/build-module/components/global-styles/border-panel.js.map +1 -1
  88. package/build-module/components/global-styles/dimensions-panel.js +278 -22
  89. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  90. package/build-module/components/global-styles/hooks.js +4 -4
  91. package/build-module/components/global-styles/hooks.js.map +1 -1
  92. package/build-module/components/global-styles/screen-color-palette.js +1 -1
  93. package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
  94. package/build-module/components/global-styles/screen-colors.js +51 -7
  95. package/build-module/components/global-styles/screen-colors.js.map +1 -1
  96. package/build-module/components/global-styles/screen-heading-color.js +143 -0
  97. package/build-module/components/global-styles/screen-heading-color.js.map +1 -0
  98. package/build-module/components/global-styles/screen-typography-element.js +4 -0
  99. package/build-module/components/global-styles/screen-typography-element.js.map +1 -1
  100. package/build-module/components/global-styles/screen-typography.js +5 -0
  101. package/build-module/components/global-styles/screen-typography.js.map +1 -1
  102. package/build-module/components/global-styles/typography-panel.js +83 -15
  103. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  104. package/build-module/components/global-styles/typography-utils.js +204 -0
  105. package/build-module/components/global-styles/typography-utils.js.map +1 -0
  106. package/build-module/components/global-styles/ui.js +10 -0
  107. package/build-module/components/global-styles/ui.js.map +1 -1
  108. package/build-module/components/global-styles/use-global-styles-output.js +182 -61
  109. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  110. package/build-module/components/global-styles/utils.js +82 -5
  111. package/build-module/components/global-styles/utils.js.map +1 -1
  112. package/build-module/components/header/document-actions/index.js +1 -0
  113. package/build-module/components/header/document-actions/index.js.map +1 -1
  114. package/build-module/components/header/index.js +30 -14
  115. package/build-module/components/header/index.js.map +1 -1
  116. package/build-module/components/header/mode-switcher/index.js +0 -4
  117. package/build-module/components/header/mode-switcher/index.js.map +1 -1
  118. package/build-module/components/header/more-menu/index.js +13 -3
  119. package/build-module/components/header/more-menu/index.js.map +1 -1
  120. package/build-module/components/header/undo-redo/redo.js +3 -2
  121. package/build-module/components/header/undo-redo/redo.js.map +1 -1
  122. package/build-module/components/list/actions/index.js +1 -1
  123. package/build-module/components/list/actions/index.js.map +1 -1
  124. package/build-module/components/save-button/index.js +3 -4
  125. package/build-module/components/save-button/index.js.map +1 -1
  126. package/build-module/components/sidebar/default-sidebar.js +9 -1
  127. package/build-module/components/sidebar/default-sidebar.js.map +1 -1
  128. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js +3 -3
  129. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
  130. package/build-module/components/sidebar/plugin-sidebar/index.js +9 -1
  131. package/build-module/components/sidebar/plugin-sidebar/index.js.map +1 -1
  132. package/build-module/components/sidebar/template-card/template-actions.js +1 -1
  133. package/build-module/components/sidebar/template-card/template-actions.js.map +1 -1
  134. package/build-module/components/template-details/edit-template-title.js +1 -1
  135. package/build-module/components/template-details/edit-template-title.js.map +1 -1
  136. package/build-module/components/template-details/index.js +19 -10
  137. package/build-module/components/template-details/index.js.map +1 -1
  138. package/build-module/components/template-details/template-areas.js +1 -1
  139. package/build-module/components/template-details/template-areas.js.map +1 -1
  140. package/build-module/components/template-details/template-part-area-selector.js +35 -0
  141. package/build-module/components/template-details/template-part-area-selector.js.map +1 -0
  142. package/build-module/components/template-part-converter/convert-to-template-part.js +3 -1
  143. package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
  144. package/build-module/hooks/index.js +1 -0
  145. package/build-module/hooks/index.js.map +1 -1
  146. package/build-module/hooks/template-part-edit.js +67 -0
  147. package/build-module/hooks/template-part-edit.js.map +1 -0
  148. package/build-module/index.js +1 -1
  149. package/build-module/index.js.map +1 -1
  150. package/build-style/style-rtl.css +40 -33
  151. package/build-style/style.css +40 -33
  152. package/package.json +29 -29
  153. package/src/components/add-new-template/add-custom-template-modal.js +39 -48
  154. package/src/components/add-new-template/new-template.js +50 -58
  155. package/src/components/add-new-template/style.scss +20 -8
  156. package/src/components/add-new-template/utils.js +529 -231
  157. package/src/components/block-editor/index.js +0 -2
  158. package/src/components/block-editor/resizable-editor.js +28 -18
  159. package/src/components/editor/style.scss +1 -0
  160. package/src/components/global-styles/border-panel.js +3 -3
  161. package/src/components/global-styles/dimensions-panel.js +344 -45
  162. package/src/components/global-styles/hooks.js +6 -3
  163. package/src/components/global-styles/screen-color-palette.js +1 -1
  164. package/src/components/global-styles/screen-colors.js +46 -4
  165. package/src/components/global-styles/screen-heading-color.js +201 -0
  166. package/src/components/global-styles/screen-typography-element.js +4 -0
  167. package/src/components/global-styles/screen-typography.js +6 -0
  168. package/src/components/global-styles/style.scss +14 -6
  169. package/src/components/global-styles/test/typography-utils.js +130 -0
  170. package/src/components/global-styles/test/use-global-styles-output.js +143 -4
  171. package/src/components/global-styles/test/utils.js +68 -8
  172. package/src/components/global-styles/typography-panel.js +119 -48
  173. package/src/components/global-styles/typography-utils.js +228 -0
  174. package/src/components/global-styles/ui.js +13 -0
  175. package/src/components/global-styles/use-global-styles-output.js +203 -53
  176. package/src/components/global-styles/utils.js +70 -4
  177. package/src/components/header/document-actions/index.js +3 -0
  178. package/src/components/header/index.js +41 -14
  179. package/src/components/header/mode-switcher/index.js +0 -3
  180. package/src/components/header/more-menu/index.js +7 -2
  181. package/src/components/header/style.scss +5 -3
  182. package/src/components/header/undo-redo/redo.js +6 -2
  183. package/src/components/list/actions/index.js +3 -1
  184. package/src/components/save-button/index.js +10 -13
  185. package/src/components/sidebar/default-sidebar.js +12 -0
  186. package/src/components/sidebar/navigation-menu-sidebar/navigation-menu.js +1 -5
  187. package/src/components/sidebar/plugin-sidebar/index.js +12 -0
  188. package/src/components/sidebar/style.scss +4 -0
  189. package/src/components/sidebar/template-card/template-actions.js +3 -1
  190. package/src/components/template-details/edit-template-title.js +7 -3
  191. package/src/components/template-details/index.js +23 -8
  192. package/src/components/template-details/style.scss +0 -5
  193. package/src/components/template-details/template-areas.js +3 -1
  194. package/src/components/template-details/template-part-area-selector.js +38 -0
  195. package/src/components/template-part-converter/convert-to-template-part.js +3 -1
  196. package/src/hooks/index.js +1 -0
  197. package/src/hooks/template-part-edit.js +82 -0
  198. package/src/index.js +1 -1
  199. package/src/style.scss +0 -1
  200. package/build/components/edit-template-part-menu-button/index.js +0 -90
  201. package/build/components/edit-template-part-menu-button/index.js.map +0 -1
  202. package/build-module/components/edit-template-part-menu-button/index.js +0 -72
  203. package/build-module/components/edit-template-part-menu-button/index.js.map +0 -1
  204. package/src/components/edit-template-part-menu-button/index.js +0 -82
@@ -3,19 +3,21 @@ import { createElement, Fragment } from "@wordpress/element";
3
3
  /**
4
4
  * WordPress dependencies
5
5
  */
6
+ import apiFetch from '@wordpress/api-fetch';
7
+ import { addQueryArgs } from '@wordpress/url';
6
8
  import { DropdownMenu, MenuGroup, MenuItem, NavigableMenu } from '@wordpress/components';
7
9
  import { useState } from '@wordpress/element';
8
10
  import { useDispatch } from '@wordpress/data';
9
11
  import { store as coreStore } from '@wordpress/core-data';
10
12
  import { archive, blockMeta, category, home, list, media, notFound, page, post, postAuthor, postDate, search, tag, layout as customGenericTemplateIcon } from '@wordpress/icons';
11
- import { __ } from '@wordpress/i18n';
13
+ import { __, sprintf } from '@wordpress/i18n';
12
14
  import { store as noticesStore } from '@wordpress/notices';
13
15
  /**
14
16
  * Internal dependencies
15
17
  */
16
18
 
17
19
  import AddCustomTemplateModal from './add-custom-template-modal';
18
- import { useExistingTemplates, useDefaultTemplateTypes, entitiesConfig, usePostTypes, usePostTypePage, useTaxonomies, useTaxonomyCategory, useTaxonomyTag, useExtraTemplates } from './utils';
20
+ import { useExistingTemplates, useDefaultTemplateTypes, useTaxonomiesMenuItems, usePostTypeMenuItems, useAuthorMenuItem } from './utils';
19
21
  import AddCustomGenericTemplateModal from './add-custom-generic-template-modal';
20
22
  import { useHistory } from '../routes';
21
23
  import { store as editSiteStore } from '../../store';
@@ -47,7 +49,8 @@ export default function NewTemplate(_ref) {
47
49
  saveEntityRecord
48
50
  } = useDispatch(coreStore);
49
51
  const {
50
- createErrorNotice
52
+ createErrorNotice,
53
+ createSuccessNotice
51
54
  } = useDispatch(noticesStore);
52
55
  const {
53
56
  setTemplate
@@ -60,14 +63,29 @@ export default function NewTemplate(_ref) {
60
63
  const {
61
64
  title,
62
65
  description,
63
- slug
66
+ slug,
67
+ templatePrefix
64
68
  } = template;
69
+ let templateContent = template.content; // Try to find fallback content from existing templates.
70
+
71
+ if (!templateContent) {
72
+ const fallbackTemplate = await apiFetch({
73
+ path: addQueryArgs('/wp/v2/templates/lookup', {
74
+ slug,
75
+ is_custom: !isWPSuggestion,
76
+ template_prefix: templatePrefix
77
+ })
78
+ });
79
+ templateContent = fallbackTemplate.content;
80
+ }
81
+
65
82
  const newTemplate = await saveEntityRecord('postType', 'wp_template', {
66
83
  description,
67
84
  // Slugs need to be strings, so this is for template `404`
68
85
  slug: slug.toString(),
69
86
  status: 'publish',
70
87
  title,
88
+ content: templateContent,
71
89
  // This adds a post meta field in template that is part of `is_custom` value calculation.
72
90
  is_wp_suggestion: isWPSuggestion
73
91
  }, {
@@ -79,7 +97,11 @@ export default function NewTemplate(_ref) {
79
97
  history.push({
80
98
  postId: newTemplate.id,
81
99
  postType: newTemplate.type
82
- }); // TODO: Add a success notice?
100
+ });
101
+ createSuccessNotice(sprintf( // translators: %s: Title of the created template e.g: "Category".
102
+ __('"%s" successfully created.'), title), {
103
+ type: 'snackbar'
104
+ });
83
105
  } catch (error) {
84
106
  const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : __('An error occurred while creating the template.');
85
107
  createErrorNotice(errorMessage, {
@@ -141,11 +163,6 @@ export default function NewTemplate(_ref) {
141
163
  }
142
164
 
143
165
  function useMissingTemplates(setEntityForSuggestions, setShowCustomTemplateModal) {
144
- const postTypes = usePostTypes();
145
- const pagePostType = usePostTypePage();
146
- const taxonomies = useTaxonomies();
147
- const categoryTaxonomy = useTaxonomyCategory();
148
- const tagTaxonomy = useTaxonomyTag();
149
166
  const existingTemplates = useExistingTemplates();
150
167
  const defaultTemplateTypes = useDefaultTemplateTypes();
151
168
  const existingTemplateSlugs = (existingTemplates || []).map(_ref2 => {
@@ -159,41 +176,44 @@ function useMissingTemplates(setEntityForSuggestions, setShowCustomTemplateModal
159
176
  const onClickMenuItem = _entityForSuggestions => {
160
177
  setShowCustomTemplateModal(true);
161
178
  setEntityForSuggestions(_entityForSuggestions);
162
- }; // TODO: find better names for these variables. `useExtraTemplates` returns an array of items.
163
-
164
-
165
- const categoryMenuItem = useExtraTemplates(categoryTaxonomy, entitiesConfig.category, onClickMenuItem);
166
- const tagMenuItem = useExtraTemplates(tagTaxonomy, entitiesConfig.tag, onClickMenuItem);
167
- const pageMenuItem = useExtraTemplates(pagePostType, entitiesConfig.page, onClickMenuItem); // We need to replace existing default template types with
179
+ }; // We need to replace existing default template types with
168
180
  // the create specific template functionality. The original
169
181
  // info (title, description, etc.) is preserved in the
170
- // `useExtraTemplates` hook.
182
+ // used hooks.
183
+
171
184
 
172
185
  const enhancedMissingDefaultTemplateTypes = [...missingDefaultTemplates];
173
- [categoryMenuItem, tagMenuItem, pageMenuItem].forEach(menuItem => {
174
- if (!(menuItem !== null && menuItem !== void 0 && menuItem.length)) {
186
+ const {
187
+ defaultTaxonomiesMenuItems,
188
+ taxonomiesMenuItems
189
+ } = useTaxonomiesMenuItems(onClickMenuItem);
190
+ const {
191
+ defaultPostTypesMenuItems,
192
+ postTypesMenuItems
193
+ } = usePostTypeMenuItems(onClickMenuItem);
194
+ const authorMenuItem = useAuthorMenuItem(onClickMenuItem);
195
+ [...defaultTaxonomiesMenuItems, ...defaultPostTypesMenuItems, authorMenuItem].forEach(menuItem => {
196
+ if (!menuItem) {
175
197
  return;
176
198
  }
177
199
 
178
- const matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(template => template.slug === menuItem[0].slug); // Some default template types might have been filtered above from
200
+ const matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(template => template.slug === menuItem.slug); // Some default template types might have been filtered above from
179
201
  // `missingDefaultTemplates` because they only check for the general
180
202
  // template. So here we either replace or append the item, augmented
181
203
  // with the check if it has available specific item to create a
182
204
  // template for.
183
205
 
184
206
  if (matchIndex > -1) {
185
- enhancedMissingDefaultTemplateTypes.splice(matchIndex, 1, menuItem[0]);
207
+ enhancedMissingDefaultTemplateTypes[matchIndex] = menuItem;
186
208
  } else {
187
- enhancedMissingDefaultTemplateTypes.push(menuItem[0]);
209
+ enhancedMissingDefaultTemplateTypes.push(menuItem);
188
210
  }
189
211
  }); // Update the sort order to match the DEFAULT_TEMPLATE_SLUGS order.
190
212
 
191
213
  enhancedMissingDefaultTemplateTypes === null || enhancedMissingDefaultTemplateTypes === void 0 ? void 0 : enhancedMissingDefaultTemplateTypes.sort((template1, template2) => {
192
214
  return DEFAULT_TEMPLATE_SLUGS.indexOf(template1.slug) - DEFAULT_TEMPLATE_SLUGS.indexOf(template2.slug);
193
215
  });
194
- const extraPostTypeTemplates = useExtraTemplates(postTypes, entitiesConfig.postType, onClickMenuItem);
195
- const extraTaxonomyTemplates = useExtraTemplates(taxonomies, entitiesConfig.taxonomy, onClickMenuItem);
196
- const missingTemplates = [...enhancedMissingDefaultTemplateTypes, ...extraPostTypeTemplates, ...extraTaxonomyTemplates];
216
+ const missingTemplates = [...enhancedMissingDefaultTemplateTypes, ...postTypesMenuItems, ...taxonomiesMenuItems];
197
217
  return missingTemplates;
198
218
  }
199
219
  //# sourceMappingURL=new-template.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["DropdownMenu","MenuGroup","MenuItem","NavigableMenu","useState","useDispatch","store","coreStore","archive","blockMeta","category","home","list","media","notFound","page","post","postAuthor","postDate","search","tag","layout","customGenericTemplateIcon","__","noticesStore","AddCustomTemplateModal","useExistingTemplates","useDefaultTemplateTypes","entitiesConfig","usePostTypes","usePostTypePage","useTaxonomies","useTaxonomyCategory","useTaxonomyTag","useExtraTemplates","AddCustomGenericTemplateModal","useHistory","editSiteStore","DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","single","index","author","taxonomy","date","attachment","NewTemplate","postType","showCustomTemplateModal","setShowCustomTemplateModal","showCustomGenericTemplateModal","setShowCustomGenericTemplateModal","entityForSuggestions","setEntityForSuggestions","history","saveEntityRecord","createErrorNotice","setTemplate","createTemplate","template","isWPSuggestion","title","description","slug","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","postTypes","pagePostType","taxonomies","categoryTaxonomy","tagTaxonomy","existingTemplates","defaultTemplateTypes","existingTemplateSlugs","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","categoryMenuItem","tagMenuItem","pageMenuItem","enhancedMissingDefaultTemplateTypes","forEach","menuItem","matchIndex","findIndex","splice","sort","template1","template2","indexOf","extraPostTypeTemplates","extraTaxonomyTemplates"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,YADD,EAECC,SAFD,EAGCC,QAHD,EAICC,aAJD,QAKO,uBALP;AAMA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,WAAT,QAA4B,iBAA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,CAAE,CAAF,CAAR,CAAc3C,IAD9B,CAAnB,CAJwE,CAOxE;AACA;AACA;AACA;AACA;;AACA,QAAK4C,UAAU,GAAG,CAAC,CAAnB,EAAuB;AACtBH,MAAAA,mCAAmC,CAACK,MAApC,CACCF,UADD,EAEC,CAFD,EAGCD,QAAQ,CAAE,CAAF,CAHT;AAKA,KAND,MAMO;AACNF,MAAAA,mCAAmC,CAAClC,IAApC,CAA0CoC,QAAQ,CAAE,CAAF,CAAlD;AACA;AACD,GArBD,EA5CC,CAkED;;AACAF,EAAAA,mCAAmC,SAAnC,IAAAA,mCAAmC,WAAnC,YAAAA,mCAAmC,CAAEM,IAArC,CAA2C,CAAEC,SAAF,EAAaC,SAAb,KAA4B;AACtE,WACC1E,sBAAsB,CAAC2E,OAAvB,CAAgCF,SAAS,CAAChD,IAA1C,IACAzB,sBAAsB,CAAC2E,OAAvB,CAAgCD,SAAS,CAACjD,IAA1C,CAFD;AAIA,GALD;AAMA,QAAMmD,sBAAsB,GAAGhF,iBAAiB,CAC/CsD,SAD+C,EAE/C5D,cAAc,CAACmB,QAFgC,EAG/CoD,eAH+C,CAAhD;AAKA,QAAMgB,sBAAsB,GAAGjF,iBAAiB,CAC/CwD,UAD+C,EAE/C9D,cAAc,CAACe,QAFgC,EAG/CwD,eAH+C,CAAhD;AAKA,QAAMtB,gBAAgB,GAAG,CACxB,GAAG2B,mCADqB,EAExB,GAAGU,sBAFqB,EAGxB,GAAGC,sBAHqB,CAAzB;AAKA,SAAOtC,gBAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\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 { __ } 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\tentitiesConfig,\n\tusePostTypes,\n\tusePostTypePage,\n\tuseTaxonomies,\n\tuseTaxonomyCategory,\n\tuseTaxonomyTag,\n\tuseExtraTemplates,\n} from './utils';\nimport AddCustomGenericTemplateModal from './add-custom-generic-template-modal';\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\n\tconst history = useHistory();\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst { setTemplate } = useDispatch( editSiteStore );\n\n\tasync function createTemplate( template, isWPSuggestion = true ) {\n\t\ttry {\n\t\t\tconst { title, description, slug } = template;\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\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\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: __( '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}\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<NavigableMenu className=\"edit-site-new-template-dropdown__popover\">\n\t\t\t\t\t\t<MenuGroup label={ postType.labels.add_new_item }>\n\t\t\t\t\t\t\t{ missingTemplates.map( ( template ) => {\n\t\t\t\t\t\t\t\tconst {\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\tslug,\n\t\t\t\t\t\t\t\t\tonClick,\n\t\t\t\t\t\t\t\t\ticon,\n\t\t\t\t\t\t\t\t} = template;\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\t\t\ticon ||\n\t\t\t\t\t\t\t\t\t\t\tTEMPLATE_ICONS[ slug ] ||\n\t\t\t\t\t\t\t\t\t\t\tpost\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\t\tinfo={ description }\n\t\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t\tonClick\n\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: createTemplate( template )\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\t\t{ title }\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\ticon={ customGenericTemplateIcon }\n\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\tinfo={ __(\n\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) }\n\t\t\t\t\t\t\t\tkey=\"custom-template\"\n\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\tsetShowCustomGenericTemplateModal( true )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Custom template' ) }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t</NavigableMenu>\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/>\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/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction useMissingTemplates(\n\tsetEntityForSuggestions,\n\tsetShowCustomTemplateModal\n) {\n\tconst postTypes = usePostTypes();\n\tconst pagePostType = usePostTypePage();\n\tconst taxonomies = useTaxonomies();\n\tconst categoryTaxonomy = useTaxonomyCategory();\n\tconst tagTaxonomy = useTaxonomyTag();\n\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\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// TODO: find better names for these variables. `useExtraTemplates` returns an array of items.\n\tconst categoryMenuItem = useExtraTemplates(\n\t\tcategoryTaxonomy,\n\t\tentitiesConfig.category,\n\t\tonClickMenuItem\n\t);\n\tconst tagMenuItem = useExtraTemplates(\n\t\ttagTaxonomy,\n\t\tentitiesConfig.tag,\n\t\tonClickMenuItem\n\t);\n\tconst pageMenuItem = useExtraTemplates(\n\t\tpagePostType,\n\t\tentitiesConfig.page,\n\t\tonClickMenuItem\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// `useExtraTemplates` hook.\n\tconst enhancedMissingDefaultTemplateTypes = [ ...missingDefaultTemplates ];\n\t[ categoryMenuItem, tagMenuItem, pageMenuItem ].forEach( ( menuItem ) => {\n\t\tif ( ! menuItem?.length ) {\n\t\t\treturn;\n\t\t}\n\t\tconst matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(\n\t\t\t( template ) => template.slug === menuItem[ 0 ].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.splice(\n\t\t\t\tmatchIndex,\n\t\t\t\t1,\n\t\t\t\tmenuItem[ 0 ]\n\t\t\t);\n\t\t} else {\n\t\t\tenhancedMissingDefaultTemplateTypes.push( menuItem[ 0 ] );\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 extraPostTypeTemplates = useExtraTemplates(\n\t\tpostTypes,\n\t\tentitiesConfig.postType,\n\t\tonClickMenuItem\n\t);\n\tconst extraTaxonomyTemplates = useExtraTemplates(\n\t\ttaxonomies,\n\t\tentitiesConfig.taxonomy,\n\t\tonClickMenuItem\n\t);\n\tconst missingTemplates = [\n\t\t...enhancedMissingDefaultTemplateTypes,\n\t\t...extraPostTypeTemplates,\n\t\t...extraTaxonomyTemplates,\n\t];\n\treturn missingTemplates;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["apiFetch","addQueryArgs","DropdownMenu","MenuGroup","MenuItem","NavigableMenu","useState","useDispatch","store","coreStore","archive","blockMeta","category","home","list","media","notFound","page","post","postAuthor","postDate","search","tag","layout","customGenericTemplateIcon","__","sprintf","noticesStore","AddCustomTemplateModal","useExistingTemplates","useDefaultTemplateTypes","useTaxonomiesMenuItems","usePostTypeMenuItems","useAuthorMenuItem","AddCustomGenericTemplateModal","useHistory","editSiteStore","DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","single","index","author","taxonomy","date","attachment","NewTemplate","postType","showCustomTemplateModal","setShowCustomTemplateModal","showCustomGenericTemplateModal","setShowCustomGenericTemplateModal","entityForSuggestions","setEntityForSuggestions","history","saveEntityRecord","createErrorNotice","createSuccessNotice","setTemplate","createTemplate","template","isWPSuggestion","title","description","slug","templatePrefix","templateContent","content","fallbackTemplate","path","is_custom","template_prefix","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","existingTemplates","defaultTemplateTypes","existingTemplateSlugs","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","enhancedMissingDefaultTemplateTypes","defaultTaxonomiesMenuItems","taxonomiesMenuItems","defaultPostTypesMenuItems","postTypesMenuItems","authorMenuItem","forEach","menuItem","matchIndex","findIndex","sort","template1","template2","indexOf"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,SACCC,YADD,EAECC,SAFD,EAGCC,QAHD,EA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ADrB;AAGA,QAAMO,cAAc,GAAG3E,iBAAiB,CAAEoE,eAAF,CAAxC;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,CAChBrD,QAAF,IAAgBA,QAAQ,CAACI,IAAT,KAAkB+C,QAAQ,CAAC/C,IADzB,CAAnB,CAJ0B,CAO1B;AACA;AACA;AACA;AACA;;AACA,QAAKgD,UAAU,GAAG,CAAC,CAAnB,EAAuB;AACtBR,MAAAA,mCAAmC,CAAEQ,UAAF,CAAnC,GAAoDD,QAApD;AACA,KAFD,MAEO;AACNP,MAAAA,mCAAmC,CAAC1B,IAApC,CAA0CiC,QAA1C;AACA;AACD,GArBD,EA1BC,CAgDD;;AACAP,EAAAA,mCAAmC,SAAnC,IAAAA,mCAAmC,WAAnC,YAAAA,mCAAmC,CAAEU,IAArC,CAA2C,CAAEC,SAAF,EAAaC,SAAb,KAA4B;AACtE,WACC9E,sBAAsB,CAAC+E,OAAvB,CAAgCF,SAAS,CAACnD,IAA1C,IACA1B,sBAAsB,CAAC+E,OAAvB,CAAgCD,SAAS,CAACpD,IAA1C,CAFD;AAIA,GALD;AAMA,QAAMqB,gBAAgB,GAAG,CACxB,GAAGmB,mCADqB,EAExB,GAAGI,kBAFqB,EAGxB,GAAGF,mBAHqB,CAAzB;AAKA,SAAOrB,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} from './utils';\nimport AddCustomGenericTemplateModal from './add-custom-generic-template-modal';\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\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\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;\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}\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<NavigableMenu className=\"edit-site-new-template-dropdown__popover\">\n\t\t\t\t\t\t<MenuGroup label={ postType.labels.add_new_item }>\n\t\t\t\t\t\t\t{ missingTemplates.map( ( template ) => {\n\t\t\t\t\t\t\t\tconst {\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\tslug,\n\t\t\t\t\t\t\t\t\tonClick,\n\t\t\t\t\t\t\t\t\ticon,\n\t\t\t\t\t\t\t\t} = template;\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\t\t\ticon ||\n\t\t\t\t\t\t\t\t\t\t\tTEMPLATE_ICONS[ slug ] ||\n\t\t\t\t\t\t\t\t\t\t\tpost\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\t\tinfo={ description }\n\t\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t\tonClick\n\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: createTemplate( template )\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\t\t{ title }\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\ticon={ customGenericTemplateIcon }\n\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\tinfo={ __(\n\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) }\n\t\t\t\t\t\t\t\tkey=\"custom-template\"\n\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\tsetShowCustomGenericTemplateModal( true )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Custom template' ) }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t</NavigableMenu>\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/>\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/>\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...postTypesMenuItems,\n\t\t...taxonomiesMenuItems,\n\t];\n\treturn missingTemplates;\n}\n"]}