@wordpress/edit-site 4.12.1-next.d6164808d3.0 → 4.14.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 (92) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/components/add-new-template/new-template.js +1 -1
  3. package/build/components/add-new-template/new-template.js.map +1 -1
  4. package/build/components/add-new-template/utils.js +90 -52
  5. package/build/components/add-new-template/utils.js.map +1 -1
  6. package/build/components/block-editor/index.js +20 -10
  7. package/build/components/block-editor/index.js.map +1 -1
  8. package/build/components/block-editor/resizable-editor.js +8 -1
  9. package/build/components/block-editor/resizable-editor.js.map +1 -1
  10. package/build/components/editor/index.js +9 -4
  11. package/build/components/editor/index.js.map +1 -1
  12. package/build/components/global-styles/dimensions-panel.js +40 -23
  13. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  14. package/build/components/global-styles/gradients-palette-panel.js +6 -2
  15. package/build/components/global-styles/gradients-palette-panel.js.map +1 -1
  16. package/build/components/global-styles/hooks.js +5 -3
  17. package/build/components/global-styles/hooks.js.map +1 -1
  18. package/build/components/global-styles/preview.js +2 -2
  19. package/build/components/global-styles/preview.js.map +1 -1
  20. package/build/components/global-styles/use-global-styles-output.js +41 -29
  21. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  22. package/build/components/global-styles/utils.js +1 -1
  23. package/build/components/global-styles/utils.js.map +1 -1
  24. package/build/components/header/index.js +41 -5
  25. package/build/components/header/index.js.map +1 -1
  26. package/build/components/list/header.js +15 -2
  27. package/build/components/list/header.js.map +1 -1
  28. package/build/components/navigation-sidebar/navigation-panel/index.js +10 -4
  29. package/build/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
  30. package/build/components/sidebar/index.js +8 -3
  31. package/build/components/sidebar/index.js.map +1 -1
  32. package/build/components/template-part-converter/convert-to-template-part.js +16 -0
  33. package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
  34. package/build/index.js +4 -1
  35. package/build/index.js.map +1 -1
  36. package/build-module/components/add-new-template/new-template.js +2 -2
  37. package/build-module/components/add-new-template/new-template.js.map +1 -1
  38. package/build-module/components/add-new-template/utils.js +87 -52
  39. package/build-module/components/add-new-template/utils.js.map +1 -1
  40. package/build-module/components/block-editor/index.js +20 -9
  41. package/build-module/components/block-editor/index.js.map +1 -1
  42. package/build-module/components/block-editor/resizable-editor.js +9 -2
  43. package/build-module/components/block-editor/resizable-editor.js.map +1 -1
  44. package/build-module/components/editor/index.js +10 -5
  45. package/build-module/components/editor/index.js.map +1 -1
  46. package/build-module/components/global-styles/dimensions-panel.js +40 -23
  47. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  48. package/build-module/components/global-styles/gradients-palette-panel.js +6 -2
  49. package/build-module/components/global-styles/gradients-palette-panel.js.map +1 -1
  50. package/build-module/components/global-styles/hooks.js +6 -4
  51. package/build-module/components/global-styles/hooks.js.map +1 -1
  52. package/build-module/components/global-styles/preview.js +2 -2
  53. package/build-module/components/global-styles/preview.js.map +1 -1
  54. package/build-module/components/global-styles/use-global-styles-output.js +42 -30
  55. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  56. package/build-module/components/global-styles/utils.js +1 -1
  57. package/build-module/components/global-styles/utils.js.map +1 -1
  58. package/build-module/components/header/index.js +42 -7
  59. package/build-module/components/header/index.js.map +1 -1
  60. package/build-module/components/list/header.js +14 -2
  61. package/build-module/components/list/header.js.map +1 -1
  62. package/build-module/components/navigation-sidebar/navigation-panel/index.js +11 -5
  63. package/build-module/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
  64. package/build-module/components/sidebar/index.js +7 -3
  65. package/build-module/components/sidebar/index.js.map +1 -1
  66. package/build-module/components/template-part-converter/convert-to-template-part.js +16 -1
  67. package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
  68. package/build-module/index.js +4 -1
  69. package/build-module/index.js.map +1 -1
  70. package/build-style/style-rtl.css +28 -16
  71. package/build-style/style.css +28 -16
  72. package/package.json +29 -29
  73. package/src/components/add-new-template/new-template.js +2 -0
  74. package/src/components/add-new-template/utils.js +82 -20
  75. package/src/components/block-editor/index.js +34 -16
  76. package/src/components/block-editor/resizable-editor.js +10 -3
  77. package/src/components/code-editor/style.scss +2 -3
  78. package/src/components/editor/index.js +12 -5
  79. package/src/components/global-styles/dimensions-panel.js +52 -31
  80. package/src/components/global-styles/gradients-palette-panel.js +25 -12
  81. package/src/components/global-styles/hooks.js +7 -7
  82. package/src/components/global-styles/preview.js +2 -2
  83. package/src/components/global-styles/use-global-styles-output.js +66 -57
  84. package/src/components/global-styles/utils.js +1 -1
  85. package/src/components/header/index.js +61 -21
  86. package/src/components/header/style.scss +9 -0
  87. package/src/components/list/header.js +15 -5
  88. package/src/components/navigation-sidebar/navigation-panel/index.js +30 -24
  89. package/src/components/sidebar/index.js +23 -20
  90. package/src/components/template-part-converter/convert-to-template-part.js +14 -1
  91. package/src/index.js +4 -0
  92. package/src/style.scss +1 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.14.0 (2022-09-13)
6
+
7
+ ## 4.13.0 (2022-08-24)
8
+
5
9
  ## 4.12.0 (2022-08-10)
6
10
 
7
11
  ## 4.11.0 (2022-07-27)
@@ -235,7 +235,7 @@ function useMissingTemplates(setEntityForSuggestions, setShowCustomTemplateModal
235
235
  enhancedMissingDefaultTemplateTypes === null || enhancedMissingDefaultTemplateTypes === void 0 ? void 0 : enhancedMissingDefaultTemplateTypes.sort((template1, template2) => {
236
236
  return DEFAULT_TEMPLATE_SLUGS.indexOf(template1.slug) - DEFAULT_TEMPLATE_SLUGS.indexOf(template2.slug);
237
237
  });
238
- const missingTemplates = [...enhancedMissingDefaultTemplateTypes, ...postTypesMenuItems, ...taxonomiesMenuItems];
238
+ const missingTemplates = [...enhancedMissingDefaultTemplateTypes, ...(0, _utils.usePostTypeArchiveMenuItems)(), ...postTypesMenuItems, ...taxonomiesMenuItems];
239
239
  return missingTemplates;
240
240
  }
241
241
  //# sourceMappingURL=new-template.js.map
@@ -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","history","saveEntityRecord","coreStore","createErrorNotice","createSuccessNotice","noticesStore","setTemplate","editSiteStore","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","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;;AAgBA;;AACA;;AAKA;;AACA;;AAOA;;AACA;;AACA;;AA9CA;AACA;AACA;;AA+BA;AACA;AACA;AAaA,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,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5C;AACA,QAAM;AAAEM,IAAAA,0BAAF;AAA8BC,IAAAA;AAA9B,MACL,mCAAwBJ,eAAxB,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,CAChBtD,QAAF,IAAgBA,QAAQ,CAACI,IAAT,KAAkBgD,QAAQ,CAAChD,IADzB,CAAnB,CAJ0B,CAO1B;AACA;AACA;AACA;AACA;;AACA,QAAKiD,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,WACC/F,sBAAsB,CAACgG,OAAvB,CAAgCF,SAAS,CAACpD,IAA1C,IACA1C,sBAAsB,CAACgG,OAAvB,CAAgCD,SAAS,CAACrD,IAA1C,CAFD;AAIA,GALD;AAMA,QAAMqB,gBAAgB,GAAG,CACxB,GAAGoB,mCADqB,EAExB,GAAGI,kBAFqB,EAGxB,GAAGF,mBAHqB,CAAzB;AAKA,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} 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"]}
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","history","saveEntityRecord","coreStore","createErrorNotice","createSuccessNotice","noticesStore","setTemplate","editSiteStore","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","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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AACgG,OAAvB,CAAgCF,SAAS,CAACpD,IAA1C,IACA1C,sBAAsB,CAACgG,OAAvB,CAAgCD,SAAS,CAACrD,IAA1C,CAFD;AAIA,GALD;AAMA,QAAMqB,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 { 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...usePostTypeArchiveMenuItems(),\n\t\t...postTypesMenuItems,\n\t\t...taxonomiesMenuItems,\n\t];\n\treturn missingTemplates;\n}\n"]}
@@ -5,7 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.mapToIHasNameAndId = void 0;
7
7
  exports.useAuthorMenuItem = useAuthorMenuItem;
8
- exports.useTaxonomiesMenuItems = exports.usePostTypeMenuItems = exports.useExistingTemplates = exports.useDefaultTemplateTypes = void 0;
8
+ exports.useExistingTemplates = exports.useDefaultTemplateTypes = void 0;
9
+ exports.usePostTypeArchiveMenuItems = usePostTypeArchiveMenuItems;
10
+ exports.useTaxonomiesMenuItems = exports.usePostTypeMenuItems = void 0;
9
11
 
10
12
  var _lodash = require("lodash");
11
13
 
@@ -104,15 +106,67 @@ const usePublicTaxonomies = () => {
104
106
  }, [taxonomies]);
105
107
  };
106
108
 
109
+ function usePostTypeNeedsUniqueIdentifier(publicPostTypes) {
110
+ const postTypeLabels = (0, _element.useMemo)(() => publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.reduce((accumulator, _ref3) => {
111
+ let {
112
+ labels
113
+ } = _ref3;
114
+ const singularName = labels.singular_name.toLowerCase();
115
+ accumulator[singularName] = (accumulator[singularName] || 0) + 1;
116
+ return accumulator;
117
+ }, {}));
118
+ return (0, _element.useCallback)(_ref4 => {
119
+ let {
120
+ labels,
121
+ slug
122
+ } = _ref4;
123
+ const singularName = labels.singular_name.toLowerCase();
124
+ return postTypeLabels[singularName] > 1 && singularName !== slug;
125
+ }, [postTypeLabels]);
126
+ }
127
+
128
+ function usePostTypeArchiveMenuItems() {
129
+ const publicPostTypes = usePublicPostTypes();
130
+ const postTypesWithArchives = (0, _element.useMemo)(() => publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.filter(postType => postType.has_archive), [publicPostTypes]);
131
+ const existingTemplates = useExistingTemplates();
132
+ const needsUniqueIdentifier = usePostTypeNeedsUniqueIdentifier(postTypesWithArchives);
133
+ return (0, _element.useMemo)(() => (postTypesWithArchives === null || postTypesWithArchives === void 0 ? void 0 : postTypesWithArchives.filter(postType => !(existingTemplates || []).some(existingTemplate => existingTemplate.slug === 'archive-' + postType.slug)).map(postType => {
134
+ var _postType$icon;
135
+
136
+ let title;
137
+
138
+ if (needsUniqueIdentifier(postType)) {
139
+ title = (0, _i18n.sprintf)( // translators: %1s: Name of the post type e.g: "Post"; %2s: Slug of the post type e.g: "book".
140
+ (0, _i18n.__)('Archive: %1$s (%2$s)'), postType.labels.singular_name, postType.slug);
141
+ } else {
142
+ title = (0, _i18n.sprintf)( // translators: %s: Name of the post type e.g: "Post".
143
+ (0, _i18n.__)('Archive: %s'), postType.labels.singular_name);
144
+ }
145
+
146
+ return {
147
+ slug: 'archive-' + postType.slug,
148
+ description: (0, _i18n.sprintf)( // translators: %s: Name of the post type e.g: "Post".
149
+ (0, _i18n.__)('Displays an archive with the latests posts of type: %s.'), postType.labels.singular_name),
150
+ title,
151
+ // `icon` is the `menu_icon` property of a post type. We
152
+ // only handle `dashicons` for now, even if the `menu_icon`
153
+ // also supports urls and svg as values.
154
+ icon: (_postType$icon = postType.icon) !== null && _postType$icon !== void 0 && _postType$icon.startsWith('dashicons-') ? postType.icon.slice(10) : _icons.archive,
155
+ templatePrefix: 'archive'
156
+ };
157
+ })) || [], [postTypesWithArchives, existingTemplates, needsUniqueIdentifier]);
158
+ }
159
+
107
160
  const usePostTypeMenuItems = onClickMenuItem => {
108
161
  const publicPostTypes = usePublicPostTypes();
109
162
  const existingTemplates = useExistingTemplates();
110
- const defaultTemplateTypes = useDefaultTemplateTypes(); // `page`is a special case in template hierarchy.
163
+ const defaultTemplateTypes = useDefaultTemplateTypes();
164
+ const needsUniqueIdentifier = usePostTypeNeedsUniqueIdentifier(publicPostTypes); // `page`is a special case in template hierarchy.
111
165
 
112
- const templatePrefixes = (0, _element.useMemo)(() => publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.reduce((accumulator, _ref3) => {
166
+ const templatePrefixes = (0, _element.useMemo)(() => publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.reduce((accumulator, _ref5) => {
113
167
  let {
114
168
  slug
115
- } = _ref3;
169
+ } = _ref5;
116
170
  let suffix = slug;
117
171
 
118
172
  if (slug !== 'page') {
@@ -121,28 +175,12 @@ const usePostTypeMenuItems = onClickMenuItem => {
121
175
 
122
176
  accumulator[slug] = suffix;
123
177
  return accumulator;
124
- }, {}), [publicPostTypes]); // We need to keep track of naming conflicts. If a conflict
125
- // occurs, we need to add slug.
126
-
127
- const postTypeLabels = publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.reduce((accumulator, _ref4) => {
128
- let {
129
- labels
130
- } = _ref4;
131
- const singularName = labels.singular_name.toLowerCase();
132
- accumulator[singularName] = (accumulator[singularName] || 0) + 1;
133
- return accumulator;
134
- }, {});
135
-
136
- const needsUniqueIdentifier = (labels, slug) => {
137
- const singularName = labels.singular_name.toLowerCase();
138
- return postTypeLabels[singularName] > 1 && singularName !== slug;
139
- };
140
-
178
+ }, {}), [publicPostTypes]);
141
179
  const postTypesInfo = useEntitiesInfo('postType', templatePrefixes);
142
- const existingTemplateSlugs = (existingTemplates || []).map(_ref5 => {
180
+ const existingTemplateSlugs = (existingTemplates || []).map(_ref6 => {
143
181
  let {
144
182
  slug
145
- } = _ref5;
183
+ } = _ref6;
146
184
  return slug;
147
185
  });
148
186
  const menuItems = (publicPostTypes || []).reduce((accumulator, postType) => {
@@ -157,15 +195,15 @@ const usePostTypeMenuItems = onClickMenuItem => {
157
195
  // augment it with the specific template functionality.
158
196
 
159
197
  const generalTemplateSlug = templatePrefixes[slug];
160
- const defaultTemplateType = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref6 => {
198
+ const defaultTemplateType = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref7 => {
161
199
  let {
162
200
  slug: _slug
163
- } = _ref6;
201
+ } = _ref7;
164
202
  return _slug === generalTemplateSlug;
165
203
  });
166
204
  const hasGeneralTemplate = existingTemplateSlugs === null || existingTemplateSlugs === void 0 ? void 0 : existingTemplateSlugs.includes(generalTemplateSlug);
167
205
 
168
- const _needsUniqueIdentifier = needsUniqueIdentifier(labels, slug);
206
+ const _needsUniqueIdentifier = needsUniqueIdentifier(postType);
169
207
 
170
208
  let menuItemTitle = (0, _i18n.sprintf)( // translators: %s: Name of the post type e.g: "Post".
171
209
  (0, _i18n.__)('Single item: %s'), labels.singular_name);
@@ -197,10 +235,10 @@ const usePostTypeMenuItems = onClickMenuItem => {
197
235
  slug,
198
236
  config: {
199
237
  recordNamePath: 'title.rendered',
200
- queryArgs: _ref7 => {
238
+ queryArgs: _ref8 => {
201
239
  let {
202
240
  search
203
- } = _ref7;
241
+ } = _ref8;
204
242
  return {
205
243
  _fields: 'id,title,slug,link',
206
244
  orderBy: search ? 'relevance' : 'modified',
@@ -269,10 +307,10 @@ const useTaxonomiesMenuItems = onClickMenuItem => {
269
307
  const existingTemplates = useExistingTemplates();
270
308
  const defaultTemplateTypes = useDefaultTemplateTypes(); // `category` and `post_tag` are special cases in template hierarchy.
271
309
 
272
- const templatePrefixes = (0, _element.useMemo)(() => publicTaxonomies === null || publicTaxonomies === void 0 ? void 0 : publicTaxonomies.reduce((accumulator, _ref8) => {
310
+ const templatePrefixes = (0, _element.useMemo)(() => publicTaxonomies === null || publicTaxonomies === void 0 ? void 0 : publicTaxonomies.reduce((accumulator, _ref9) => {
273
311
  let {
274
312
  slug
275
- } = _ref8;
313
+ } = _ref9;
276
314
  let suffix = slug;
277
315
 
278
316
  if (!['category', 'post_tag'].includes(slug)) {
@@ -288,10 +326,10 @@ const useTaxonomiesMenuItems = onClickMenuItem => {
288
326
  }, {}), [publicTaxonomies]); // We need to keep track of naming conflicts. If a conflict
289
327
  // occurs, we need to add slug.
290
328
 
291
- const taxonomyLabels = publicTaxonomies === null || publicTaxonomies === void 0 ? void 0 : publicTaxonomies.reduce((accumulator, _ref9) => {
329
+ const taxonomyLabels = publicTaxonomies === null || publicTaxonomies === void 0 ? void 0 : publicTaxonomies.reduce((accumulator, _ref10) => {
292
330
  let {
293
331
  labels
294
- } = _ref9;
332
+ } = _ref10;
295
333
  const singularName = labels.singular_name.toLowerCase();
296
334
  accumulator[singularName] = (accumulator[singularName] || 0) + 1;
297
335
  return accumulator;
@@ -307,10 +345,10 @@ const useTaxonomiesMenuItems = onClickMenuItem => {
307
345
  };
308
346
 
309
347
  const taxonomiesInfo = useEntitiesInfo('taxonomy', templatePrefixes);
310
- const existingTemplateSlugs = (existingTemplates || []).map(_ref10 => {
348
+ const existingTemplateSlugs = (existingTemplates || []).map(_ref11 => {
311
349
  let {
312
350
  slug
313
- } = _ref10;
351
+ } = _ref11;
314
352
  return slug;
315
353
  });
316
354
  const menuItems = (publicTaxonomies || []).reduce((accumulator, taxonomy) => {
@@ -324,10 +362,10 @@ const useTaxonomiesMenuItems = onClickMenuItem => {
324
362
  // augment it with the specific template functionality.
325
363
 
326
364
  const generalTemplateSlug = templatePrefixes[slug];
327
- const defaultTemplateType = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref11 => {
365
+ const defaultTemplateType = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref12 => {
328
366
  let {
329
367
  slug: _slug
330
- } = _ref11;
368
+ } = _ref12;
331
369
  return _slug === generalTemplateSlug;
332
370
  });
333
371
  const hasGeneralTemplate = existingTemplateSlugs === null || existingTemplateSlugs === void 0 ? void 0 : existingTemplateSlugs.includes(generalTemplateSlug);
@@ -359,10 +397,10 @@ const useTaxonomiesMenuItems = onClickMenuItem => {
359
397
  type: 'taxonomy',
360
398
  slug,
361
399
  config: {
362
- queryArgs: _ref12 => {
400
+ queryArgs: _ref13 => {
363
401
  let {
364
402
  search
365
- } = _ref12;
403
+ } = _ref13;
366
404
  return {
367
405
  _fields: 'id,name,slug,link',
368
406
  orderBy: search ? 'name' : 'count',
@@ -432,10 +470,10 @@ function useAuthorNeedsUniqueIndentifier() {
432
470
  per_page: -1
433
471
  }), []);
434
472
  const authorsCountByName = (0, _element.useMemo)(() => {
435
- return (authors || []).reduce((authorsCount, _ref13) => {
473
+ return (authors || []).reduce((authorsCount, _ref14) => {
436
474
  let {
437
475
  name
438
- } = _ref13;
476
+ } = _ref14;
439
477
  authorsCount[name] = (authorsCount[name] || 0) + 1;
440
478
  return authorsCount;
441
479
  }, {});
@@ -461,10 +499,10 @@ function useAuthorMenuItem(onClickMenuItem) {
461
499
  const defaultTemplateTypes = useDefaultTemplateTypes();
462
500
  const authorInfo = useEntitiesInfo('root', USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX, USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS);
463
501
  const authorNeedsUniqueId = useAuthorNeedsUniqueIndentifier();
464
- let authorMenuItem = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref14 => {
502
+ let authorMenuItem = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref15 => {
465
503
  let {
466
504
  slug
467
- } = _ref14;
505
+ } = _ref15;
468
506
  return slug === 'author';
469
507
  });
470
508
 
@@ -476,10 +514,10 @@ function useAuthorMenuItem(onClickMenuItem) {
476
514
  };
477
515
  }
478
516
 
479
- const hasGeneralTemplate = !!(existingTemplates !== null && existingTemplates !== void 0 && existingTemplates.find(_ref15 => {
517
+ const hasGeneralTemplate = !!(existingTemplates !== null && existingTemplates !== void 0 && existingTemplates.find(_ref16 => {
480
518
  let {
481
519
  slug
482
- } = _ref15;
520
+ } = _ref16;
483
521
  return slug === 'author';
484
522
  }));
485
523
 
@@ -493,10 +531,10 @@ function useAuthorMenuItem(onClickMenuItem) {
493
531
  type: 'root',
494
532
  slug: 'user',
495
533
  config: {
496
- queryArgs: _ref16 => {
534
+ queryArgs: _ref17 => {
497
535
  let {
498
536
  search
499
- } = _ref16;
537
+ } = _ref17;
500
538
  return {
501
539
  _fields: 'id,name,slug,link',
502
540
  orderBy: search ? 'name' : 'registered_date',
@@ -554,8 +592,8 @@ function useAuthorMenuItem(onClickMenuItem) {
554
592
  const useExistingTemplateSlugs = templatePrefixes => {
555
593
  const existingTemplates = useExistingTemplates();
556
594
  const existingSlugs = (0, _element.useMemo)(() => {
557
- return Object.entries(templatePrefixes || {}).reduce((accumulator, _ref17) => {
558
- let [slug, prefix] = _ref17;
595
+ return Object.entries(templatePrefixes || {}).reduce((accumulator, _ref18) => {
596
+ let [slug, prefix] = _ref18;
559
597
  const slugsWithTemplates = (existingTemplates || []).reduce((_accumulator, existingTemplate) => {
560
598
  const _prefix = `${prefix}-`;
561
599
 
@@ -590,8 +628,8 @@ const useTemplatesToExclude = function (entityName, templatePrefixes) {
590
628
  let additionalQueryParameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
591
629
  const slugsToExcludePerEntity = useExistingTemplateSlugs(templatePrefixes);
592
630
  const recordsToExcludePerEntity = (0, _data.useSelect)(select => {
593
- return Object.entries(slugsToExcludePerEntity || {}).reduce((accumulator, _ref18) => {
594
- let [slug, slugsWithTemplates] = _ref18;
631
+ return Object.entries(slugsToExcludePerEntity || {}).reduce((accumulator, _ref19) => {
632
+ let [slug, slugsWithTemplates] = _ref19;
595
633
  const entitiesWithTemplates = select(_coreData.store).getEntityRecords(entityName, slug, {
596
634
  _fields: 'id',
597
635
  context: 'view',
@@ -632,10 +670,10 @@ const useEntitiesInfo = function (entityName, templatePrefixes) {
632
670
  return Object.keys(templatePrefixes || {}).reduce((accumulator, slug) => {
633
671
  var _recordsToExcludePerE, _select$getEntityReco;
634
672
 
635
- const existingEntitiesIds = (recordsToExcludePerEntity === null || recordsToExcludePerEntity === void 0 ? void 0 : (_recordsToExcludePerE = recordsToExcludePerEntity[slug]) === null || _recordsToExcludePerE === void 0 ? void 0 : _recordsToExcludePerE.map(_ref19 => {
673
+ const existingEntitiesIds = (recordsToExcludePerEntity === null || recordsToExcludePerEntity === void 0 ? void 0 : (_recordsToExcludePerE = recordsToExcludePerEntity[slug]) === null || _recordsToExcludePerE === void 0 ? void 0 : _recordsToExcludePerE.map(_ref20 => {
636
674
  let {
637
675
  id
638
- } = _ref19;
676
+ } = _ref20;
639
677
  return id;
640
678
  })) || [];
641
679
  accumulator[slug] = {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/utils.js"],"names":["mapToIHasNameAndId","entities","path","map","entity","name","useExistingTemplates","select","coreStore","getEntityRecords","per_page","useDefaultTemplateTypes","editorStore","__experimentalGetDefaultTemplateTypes","usePublicPostTypes","postTypes","getPostTypes","excludedPostTypes","filter","viewable","slug","includes","usePublicTaxonomies","taxonomies","getTaxonomies","visibility","publicly_queryable","usePostTypeMenuItems","onClickMenuItem","publicPostTypes","existingTemplates","defaultTemplateTypes","templatePrefixes","reduce","accumulator","suffix","postTypeLabels","labels","singularName","singular_name","toLowerCase","needsUniqueIdentifier","postTypesInfo","useEntitiesInfo","existingTemplateSlugs","menuItems","postType","icon","generalTemplateSlug","defaultTemplateType","find","_slug","hasGeneralTemplate","_needsUniqueIdentifier","menuItemTitle","menuItem","templatePrefix","title","description","startsWith","slice","post","hasEntities","onClick","template","type","config","recordNamePath","queryArgs","search","_fields","orderBy","exclude","existingEntitiesIds","getSpecificTemplate","suggestion","push","postTypesMenuItems","key","defaultPostTypesMenuItems","useTaxonomiesMenuItems","publicTaxonomies","taxonomyLabels","taxonomiesInfo","taxonomy","blockMeta","taxonomiesMenuItems","defaultTaxonomiesMenuItems","useAuthorNeedsUniqueIndentifier","authors","getUsers","who","authorsCountByName","authorsCount","USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX","user","USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS","useAuthorMenuItem","authorInfo","authorNeedsUniqueId","authorMenuItem","needsUniqueId","search_items","not_found","all_items","useExistingTemplateSlugs","existingSlugs","Object","entries","prefix","slugsWithTemplates","_accumulator","existingTemplate","_prefix","substring","length","useTemplatesToExclude","entityName","additionalQueryParameters","slugsToExcludePerEntity","recordsToExcludePerEntity","entitiesWithTemplates","context","entitiesInfo","keys","id"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAdA;AACA;AACA;;AAGA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAG,CAAEC,QAAF,EAAYC,IAAZ,KAAsB;AACvD,SAAO,CAAED,QAAQ,IAAI,EAAd,EAAmBE,GAAnB,CAA0BC,MAAF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D,EAGtDsF,yBAHsD,CAAvD;AAKA,QAAMK,YAAY,GAAG,qBAClBpH,MAAF,IAAc;AACb,WAAOoG,MAAM,CAACiB,IAAP,CAAa5F,gBAAgB,IAAI,EAAjC,EAAsCC,MAAtC,CACN,CAAEC,WAAF,EAAed,IAAf,KAAyB;AAAA;;AACxB,YAAMqD,mBAAmB,GACxB,CAAA+C,yBAAyB,SAAzB,IAAAA,yBAAyB,WAAzB,qCAAAA,yBAAyB,CAAIpG,IAAJ,CAAzB,gFAAqCjB,GAArC,CACC;AAAA,YAAE;AAAE0H,UAAAA;AAAF,SAAF;AAAA,eAAcA,EAAd;AAAA,OADD,MAEK,EAHN;AAIA3F,MAAAA,WAAW,CAAEd,IAAF,CAAX,GAAsB;AACrB0C,QAAAA,WAAW,EAAE,CAAC,2BAAEvD,MAAM,CAAEC,eAAF,CAAN,CAAoBC,gBAApB,CACf4G,UADe,EAEfjG,IAFe,EAGf;AACCV,UAAAA,QAAQ,EAAE,CADX;AAEC4D,UAAAA,OAAO,EAAE,IAFV;AAGCoD,UAAAA,OAAO,EAAE,MAHV;AAIClD,UAAAA,OAAO,EAAEC,mBAJV;AAKC,aAAG6C,yBAAyB,CAAElG,IAAF;AAL7B,SAHe,CAAF,kDAAE,sBAUb+F,MAVW,CADO;AAYrB1C,QAAAA;AAZqB,OAAtB;AAcA,aAAOvC,WAAP;AACA,KArBK,EAsBN,EAtBM,CAAP;AAwBA,GA1BmB,EA2BpB,CAAEF,gBAAF,EAAoBwF,yBAApB,CA3BoB,CAArB;AA6BA,SAAOG,YAAP;AACA,CAxCD","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useMemo, useCallback } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { blockMeta, post } from '@wordpress/icons';\n\n/**\n * @typedef IHasNameAndId\n * @property {string|number} id The entity's id.\n * @property {string} name The entity's name.\n */\n\n/**\n * Helper util to map records to add a `name` prop from a\n * provided path, in order to handle all entities in the same\n * fashion(implementing`IHasNameAndId` interface).\n *\n * @param {Object[]} entities The array of entities.\n * @param {string} path The path to map a `name` property from the entity.\n * @return {IHasNameAndId[]} An array of enitities that now implement the `IHasNameAndId` interface.\n */\nexport const mapToIHasNameAndId = ( entities, path ) => {\n\treturn ( entities || [] ).map( ( entity ) => ( {\n\t\t...entity,\n\t\tname: decodeEntities( get( entity, path ) ),\n\t} ) );\n};\n\n/**\n * @typedef {Object} EntitiesInfo\n * @property {boolean} hasEntities If an entity has available records(posts, terms, etc..).\n * @property {number[]} existingEntitiesIds An array of the existing entities ids.\n */\n\nexport const useExistingTemplates = () => {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\tper_page: -1,\n\t\t\t} ),\n\t\t[]\n\t);\n};\n\nexport const useDefaultTemplateTypes = () => {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( editorStore ).__experimentalGetDefaultTemplateTypes(),\n\t\t[]\n\t);\n};\n\nconst usePublicPostTypes = () => {\n\tconst postTypes = useSelect(\n\t\t( select ) => select( coreStore ).getPostTypes( { per_page: -1 } ),\n\t\t[]\n\t);\n\treturn useMemo( () => {\n\t\tconst excludedPostTypes = [ 'attachment' ];\n\t\treturn postTypes?.filter(\n\t\t\t( { viewable, slug } ) =>\n\t\t\t\tviewable && ! excludedPostTypes.includes( slug )\n\t\t);\n\t}, [ postTypes ] );\n};\n\nconst usePublicTaxonomies = () => {\n\tconst taxonomies = useSelect(\n\t\t( select ) => select( coreStore ).getTaxonomies( { per_page: -1 } ),\n\t\t[]\n\t);\n\treturn useMemo( () => {\n\t\treturn taxonomies?.filter(\n\t\t\t( { visibility } ) => visibility?.publicly_queryable\n\t\t);\n\t}, [ taxonomies ] );\n};\n\nexport const usePostTypeMenuItems = ( onClickMenuItem ) => {\n\tconst publicPostTypes = usePublicPostTypes();\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\t// `page`is a special case in template hierarchy.\n\tconst templatePrefixes = useMemo(\n\t\t() =>\n\t\t\tpublicPostTypes?.reduce( ( accumulator, { slug } ) => {\n\t\t\t\tlet suffix = slug;\n\t\t\t\tif ( slug !== 'page' ) {\n\t\t\t\t\tsuffix = `single-${ suffix }`;\n\t\t\t\t}\n\t\t\t\taccumulator[ slug ] = suffix;\n\t\t\t\treturn accumulator;\n\t\t\t}, {} ),\n\t\t[ publicPostTypes ]\n\t);\n\t// We need to keep track of naming conflicts. If a conflict\n\t// occurs, we need to add slug.\n\tconst postTypeLabels = publicPostTypes?.reduce(\n\t\t( accumulator, { labels } ) => {\n\t\t\tconst singularName = labels.singular_name.toLowerCase();\n\t\t\taccumulator[ singularName ] =\n\t\t\t\t( accumulator[ singularName ] || 0 ) + 1;\n\t\t\treturn accumulator;\n\t\t},\n\t\t{}\n\t);\n\tconst needsUniqueIdentifier = ( labels, slug ) => {\n\t\tconst singularName = labels.singular_name.toLowerCase();\n\t\treturn postTypeLabels[ singularName ] > 1 && singularName !== slug;\n\t};\n\tconst postTypesInfo = useEntitiesInfo( 'postType', templatePrefixes );\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst menuItems = ( publicPostTypes || [] ).reduce(\n\t\t( accumulator, postType ) => {\n\t\t\tconst { slug, labels, icon } = postType;\n\t\t\t// We need to check if the general template is part of the\n\t\t\t// defaultTemplateTypes. If it is, just use that info and\n\t\t\t// augment it with the specific template functionality.\n\t\t\tconst generalTemplateSlug = templatePrefixes[ slug ];\n\t\t\tconst defaultTemplateType = defaultTemplateTypes?.find(\n\t\t\t\t( { slug: _slug } ) => _slug === generalTemplateSlug\n\t\t\t);\n\t\t\tconst hasGeneralTemplate =\n\t\t\t\texistingTemplateSlugs?.includes( generalTemplateSlug );\n\t\t\tconst _needsUniqueIdentifier = needsUniqueIdentifier(\n\t\t\t\tlabels,\n\t\t\t\tslug\n\t\t\t);\n\t\t\tlet menuItemTitle = sprintf(\n\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t__( 'Single item: %s' ),\n\t\t\t\tlabels.singular_name\n\t\t\t);\n\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\tmenuItemTitle = sprintf(\n\t\t\t\t\t// translators: %1s: Name of the post type e.g: \"Post\"; %2s: Slug of the post type e.g: \"book\".\n\t\t\t\t\t__( 'Single item: %1$s (%2$s)' ),\n\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\tslug\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst menuItem = defaultTemplateType\n\t\t\t\t? {\n\t\t\t\t\t\t...defaultTemplateType,\n\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t }\n\t\t\t\t: {\n\t\t\t\t\t\tslug: generalTemplateSlug,\n\t\t\t\t\t\ttitle: menuItemTitle,\n\t\t\t\t\t\tdescription: sprintf(\n\t\t\t\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t\t\t\t__( 'Displays a single item: %s.' ),\n\t\t\t\t\t\t\tlabels.singular_name\n\t\t\t\t\t\t),\n\t\t\t\t\t\t// `icon` is the `menu_icon` property of a post type. We\n\t\t\t\t\t\t// only handle `dashicons` for now, even if the `menu_icon`\n\t\t\t\t\t\t// also supports urls and svg as values.\n\t\t\t\t\t\ticon: icon?.startsWith( 'dashicons-' )\n\t\t\t\t\t\t\t? icon.slice( 10 )\n\t\t\t\t\t\t\t: post,\n\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t };\n\t\t\tconst hasEntities = postTypesInfo?.[ slug ]?.hasEntities;\n\t\t\t// We have a different template creation flow only if they have entities.\n\t\t\tif ( hasEntities ) {\n\t\t\t\tmenuItem.onClick = ( template ) => {\n\t\t\t\t\tonClickMenuItem( {\n\t\t\t\t\t\ttype: 'postType',\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\trecordNamePath: 'title.rendered',\n\t\t\t\t\t\t\tqueryArgs: ( { search } ) => {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t_fields: 'id,title,slug,link',\n\t\t\t\t\t\t\t\t\torderBy: search ? 'relevance' : 'modified',\n\t\t\t\t\t\t\t\t\texclude:\n\t\t\t\t\t\t\t\t\t\tpostTypesInfo[ slug ]\n\t\t\t\t\t\t\t\t\t\t\t.existingEntitiesIds,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tgetSpecificTemplate: ( suggestion ) => {\n\t\t\t\t\t\t\t\tlet title = sprintf(\n\t\t\t\t\t\t\t\t\t// translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the singular name of a post type and %2$s is the name of the post, e.g. \"Page: Hello\".\n\t\t\t\t\t\t\t\t\t__( '%1$s: %2$s' ),\n\t\t\t\t\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tconst description = sprintf(\n\t\t\t\t\t\t\t\t\t// translators: Represents the description of a user's custom template in the Site Editor, e.g. \"Template for Page: Hello\"\n\t\t\t\t\t\t\t\t\t__( 'Template for %1$s' ),\n\t\t\t\t\t\t\t\t\ttitle\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\t\t\t\t\t\ttitle = sprintf(\n\t\t\t\t\t\t\t\t\t\t// translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the template title and %2$s is the slug of the post type, e.g. \"Project: Hello (project_type)\"\n\t\t\t\t\t\t\t\t\t\t__( '%1$s (%2$s)' ),\n\t\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\t\tslug\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\treturn {\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: `${ templatePrefixes[ slug ] }-${ suggestion.slug }`,\n\t\t\t\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\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\tlabels,\n\t\t\t\t\t\thasGeneralTemplate,\n\t\t\t\t\t\ttemplate,\n\t\t\t\t\t} );\n\t\t\t\t};\n\t\t\t}\n\t\t\t// We don't need to add the menu item if there are no\n\t\t\t// entities and the general template exists.\n\t\t\tif ( ! hasGeneralTemplate || hasEntities ) {\n\t\t\t\taccumulator.push( menuItem );\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t},\n\t\t[]\n\t);\n\t// Split menu items into two groups: one for the default post types\n\t// and one for the rest.\n\tconst postTypesMenuItems = useMemo(\n\t\t() =>\n\t\t\tmenuItems.reduce(\n\t\t\t\t( accumulator, postType ) => {\n\t\t\t\t\tconst { slug } = postType;\n\t\t\t\t\tlet key = 'postTypesMenuItems';\n\t\t\t\t\tif ( slug === 'page' ) {\n\t\t\t\t\t\tkey = 'defaultPostTypesMenuItems';\n\t\t\t\t\t}\n\t\t\t\t\taccumulator[ key ].push( postType );\n\t\t\t\t\treturn accumulator;\n\t\t\t\t},\n\t\t\t\t{ defaultPostTypesMenuItems: [], postTypesMenuItems: [] }\n\t\t\t),\n\t\t[ menuItems ]\n\t);\n\treturn postTypesMenuItems;\n};\n\nexport const useTaxonomiesMenuItems = ( onClickMenuItem ) => {\n\tconst publicTaxonomies = usePublicTaxonomies();\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\t// `category` and `post_tag` are special cases in template hierarchy.\n\tconst templatePrefixes = useMemo(\n\t\t() =>\n\t\t\tpublicTaxonomies?.reduce( ( accumulator, { slug } ) => {\n\t\t\t\tlet suffix = slug;\n\t\t\t\tif ( ! [ 'category', 'post_tag' ].includes( slug ) ) {\n\t\t\t\t\tsuffix = `taxonomy-${ suffix }`;\n\t\t\t\t}\n\t\t\t\tif ( slug === 'post_tag' ) {\n\t\t\t\t\tsuffix = `tag`;\n\t\t\t\t}\n\t\t\t\taccumulator[ slug ] = suffix;\n\t\t\t\treturn accumulator;\n\t\t\t}, {} ),\n\t\t[ publicTaxonomies ]\n\t);\n\t// We need to keep track of naming conflicts. If a conflict\n\t// occurs, we need to add slug.\n\tconst taxonomyLabels = publicTaxonomies?.reduce(\n\t\t( accumulator, { labels } ) => {\n\t\t\tconst singularName = labels.singular_name.toLowerCase();\n\t\t\taccumulator[ singularName ] =\n\t\t\t\t( accumulator[ singularName ] || 0 ) + 1;\n\t\t\treturn accumulator;\n\t\t},\n\t\t{}\n\t);\n\tconst needsUniqueIdentifier = ( labels, slug ) => {\n\t\tif ( [ 'category', 'post_tag' ].includes( slug ) ) {\n\t\t\treturn false;\n\t\t}\n\t\tconst singularName = labels.singular_name.toLowerCase();\n\t\treturn taxonomyLabels[ singularName ] > 1 && singularName !== slug;\n\t};\n\tconst taxonomiesInfo = useEntitiesInfo( 'taxonomy', templatePrefixes );\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst menuItems = ( publicTaxonomies || [] ).reduce(\n\t\t( accumulator, taxonomy ) => {\n\t\t\tconst { slug, labels } = taxonomy;\n\t\t\t// We need to check if the general template is part of the\n\t\t\t// defaultTemplateTypes. If it is, just use that info and\n\t\t\t// augment it with the specific template functionality.\n\t\t\tconst generalTemplateSlug = templatePrefixes[ slug ];\n\t\t\tconst defaultTemplateType = defaultTemplateTypes?.find(\n\t\t\t\t( { slug: _slug } ) => _slug === generalTemplateSlug\n\t\t\t);\n\t\t\tconst hasGeneralTemplate =\n\t\t\t\texistingTemplateSlugs?.includes( generalTemplateSlug );\n\t\t\tconst _needsUniqueIdentifier = needsUniqueIdentifier(\n\t\t\t\tlabels,\n\t\t\t\tslug\n\t\t\t);\n\t\t\tlet menuItemTitle = labels.singular_name;\n\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\tmenuItemTitle = sprintf(\n\t\t\t\t\t// translators: %1s: Name of the taxonomy e.g: \"Category\"; %2s: Slug of the taxonomy e.g: \"product_cat\".\n\t\t\t\t\t__( '%1$s (%2$s)' ),\n\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\tslug\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst menuItem = defaultTemplateType\n\t\t\t\t? {\n\t\t\t\t\t\t...defaultTemplateType,\n\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t }\n\t\t\t\t: {\n\t\t\t\t\t\tslug: generalTemplateSlug,\n\t\t\t\t\t\ttitle: menuItemTitle,\n\t\t\t\t\t\tdescription: sprintf(\n\t\t\t\t\t\t\t// translators: %s: Name of the taxonomy e.g: \"Product Categories\".\n\t\t\t\t\t\t\t__( 'Displays taxonomy: %s.' ),\n\t\t\t\t\t\t\tlabels.singular_name\n\t\t\t\t\t\t),\n\t\t\t\t\t\ticon: blockMeta,\n\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t };\n\t\t\tconst hasEntities = taxonomiesInfo?.[ slug ]?.hasEntities;\n\t\t\t// We have a different template creation flow only if they have entities.\n\t\t\tif ( hasEntities ) {\n\t\t\t\tmenuItem.onClick = ( template ) => {\n\t\t\t\t\tonClickMenuItem( {\n\t\t\t\t\t\ttype: 'taxonomy',\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\tqueryArgs: ( { search } ) => {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t_fields: 'id,name,slug,link',\n\t\t\t\t\t\t\t\t\torderBy: search ? 'name' : 'count',\n\t\t\t\t\t\t\t\t\texclude:\n\t\t\t\t\t\t\t\t\t\ttaxonomiesInfo[ slug ]\n\t\t\t\t\t\t\t\t\t\t\t.existingEntitiesIds,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tgetSpecificTemplate: ( suggestion ) => {\n\t\t\t\t\t\t\t\tlet title = sprintf(\n\t\t\t\t\t\t\t\t\t// translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the singular name of a taxonomy and %2$s is the name of the term, e.g. \"Category: shoes\".\n\t\t\t\t\t\t\t\t\t__( '%1$s: %2$s' ),\n\t\t\t\t\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tconst description = sprintf(\n\t\t\t\t\t\t\t\t\t// translators: Represents the description of a user's custom template in the Site Editor, e.g. \"Template for Category: shoes\"\n\t\t\t\t\t\t\t\t\t__( 'Template for %1$s' ),\n\t\t\t\t\t\t\t\t\ttitle\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\t\t\t\t\t\ttitle = sprintf(\n\t\t\t\t\t\t\t\t\t\t// translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the template title and %2$s is the slug of the taxonomy, e.g. \"Category: shoes (product_tag)\"\n\t\t\t\t\t\t\t\t\t\t__( '%1$s (%2$s)' ),\n\t\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\t\tslug\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\treturn {\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: `${ templatePrefixes[ slug ] }-${ suggestion.slug }`,\n\t\t\t\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\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\tlabels,\n\t\t\t\t\t\thasGeneralTemplate,\n\t\t\t\t\t\ttemplate,\n\t\t\t\t\t} );\n\t\t\t\t};\n\t\t\t}\n\t\t\t// We don't need to add the menu item if there are no\n\t\t\t// entities and the general template exists.\n\t\t\tif ( ! hasGeneralTemplate || hasEntities ) {\n\t\t\t\taccumulator.push( menuItem );\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t},\n\t\t[]\n\t);\n\t// Split menu items into two groups: one for the default taxonomies\n\t// and one for the rest.\n\tconst taxonomiesMenuItems = useMemo(\n\t\t() =>\n\t\t\tmenuItems.reduce(\n\t\t\t\t( accumulator, taxonomy ) => {\n\t\t\t\t\tconst { slug } = taxonomy;\n\t\t\t\t\tlet key = 'taxonomiesMenuItems';\n\t\t\t\t\tif ( [ 'category', 'tag' ].includes( slug ) ) {\n\t\t\t\t\t\tkey = 'defaultTaxonomiesMenuItems';\n\t\t\t\t\t}\n\t\t\t\t\taccumulator[ key ].push( taxonomy );\n\t\t\t\t\treturn accumulator;\n\t\t\t\t},\n\t\t\t\t{ defaultTaxonomiesMenuItems: [], taxonomiesMenuItems: [] }\n\t\t\t),\n\t\t[ menuItems ]\n\t);\n\treturn taxonomiesMenuItems;\n};\n\nfunction useAuthorNeedsUniqueIndentifier() {\n\tconst authors = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getUsers( { who: 'authors', per_page: -1 } ),\n\t\t[]\n\t);\n\tconst authorsCountByName = useMemo( () => {\n\t\treturn ( authors || [] ).reduce( ( authorsCount, { name } ) => {\n\t\t\tauthorsCount[ name ] = ( authorsCount[ name ] || 0 ) + 1;\n\t\t\treturn authorsCount;\n\t\t}, {} );\n\t}, [ authors ] );\n\treturn useCallback(\n\t\t( name ) => {\n\t\t\treturn authorsCountByName[ name ] > 1;\n\t\t},\n\t\t[ authorsCountByName ]\n\t);\n}\n\nconst USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX = { user: 'author' };\nconst USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS = { user: { who: 'authors' } };\nexport function useAuthorMenuItem( onClickMenuItem ) {\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst authorInfo = useEntitiesInfo(\n\t\t'root',\n\t\tUSE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX,\n\t\tUSE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS\n\t);\n\tconst authorNeedsUniqueId = useAuthorNeedsUniqueIndentifier();\n\tlet authorMenuItem = defaultTemplateTypes?.find(\n\t\t( { slug } ) => slug === 'author'\n\t);\n\tif ( ! authorMenuItem ) {\n\t\tauthorMenuItem = {\n\t\t\tdescription: __(\n\t\t\t\t'Displays latest posts written by a single author.'\n\t\t\t),\n\t\t\tslug: 'author',\n\t\t\ttitle: 'Author',\n\t\t};\n\t}\n\tconst hasGeneralTemplate = !! existingTemplates?.find(\n\t\t( { slug } ) => slug === 'author'\n\t);\n\tif ( authorInfo.user?.hasEntities ) {\n\t\tauthorMenuItem = { ...authorMenuItem, templatePrefix: 'author' };\n\t\tauthorMenuItem.onClick = ( template ) => {\n\t\t\tonClickMenuItem( {\n\t\t\t\ttype: 'root',\n\t\t\t\tslug: 'user',\n\t\t\t\tconfig: {\n\t\t\t\t\tqueryArgs: ( { search } ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t_fields: 'id,name,slug,link',\n\t\t\t\t\t\t\torderBy: search ? 'name' : 'registered_date',\n\t\t\t\t\t\t\texclude: authorInfo.user.existingEntitiesIds,\n\t\t\t\t\t\t\twho: 'authors',\n\t\t\t\t\t\t};\n\t\t\t\t\t},\n\t\t\t\t\tgetSpecificTemplate: ( suggestion ) => {\n\t\t\t\t\t\tconst needsUniqueId = authorNeedsUniqueId(\n\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst title = needsUniqueId\n\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t// translators: %1$s: Represents the name of an author e.g: \"Jorge\", %2$s: Represents the slug of an author e.g: \"author-jorge-slug\".\n\t\t\t\t\t\t\t\t\t__( 'Author: %1$s (%2$s)' ),\n\t\t\t\t\t\t\t\t\tsuggestion.name,\n\t\t\t\t\t\t\t\t\tsuggestion.slug\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t\t// translators: %s: Represents the name of an author e.g: \"Jorge\".\n\t\t\t\t\t\t\t\t\t__( 'Author: %s' ),\n\t\t\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t\t );\n\t\t\t\t\t\tconst description = sprintf(\n\t\t\t\t\t\t\t// translators: %s: Represents the name of an author e.g: \"Jorge\".\n\t\t\t\t\t\t\t__( 'Template for Author: %s' ),\n\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\tslug: `author-${ suggestion.slug }`,\n\t\t\t\t\t\t\ttemplatePrefix: 'author',\n\t\t\t\t\t\t};\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tlabels: {\n\t\t\t\t\tsingular_name: __( 'Author' ),\n\t\t\t\t\tsearch_items: __( 'Search Authors' ),\n\t\t\t\t\tnot_found: __( 'No authors found.' ),\n\t\t\t\t\tall_items: __( 'All Authors' ),\n\t\t\t\t},\n\t\t\t\thasGeneralTemplate,\n\t\t\t\ttemplate,\n\t\t\t} );\n\t\t};\n\t}\n\tif ( ! hasGeneralTemplate || authorInfo.user?.hasEntities ) {\n\t\treturn authorMenuItem;\n\t}\n}\n\n/**\n * Helper hook that filters all the existing templates by the given\n * object with the entity's slug as key and the template prefix as value.\n *\n * Example:\n * `existingTemplates` is: [ { slug: 'tag-apple' }, { slug: 'page-about' }, { slug: 'tag' } ]\n * `templatePrefixes` is: { post_tag: 'tag' }\n * It will return: { post_tag: ['apple'] }\n *\n * Note: We append the `-` to the given template prefix in this function for our checks.\n *\n * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.\n * @return {Record<string,string[]>} An object with the entity's slug as key and an array with the existing template slugs as value.\n */\nconst useExistingTemplateSlugs = ( templatePrefixes ) => {\n\tconst existingTemplates = useExistingTemplates();\n\tconst existingSlugs = useMemo( () => {\n\t\treturn Object.entries( templatePrefixes || {} ).reduce(\n\t\t\t( accumulator, [ slug, prefix ] ) => {\n\t\t\t\tconst slugsWithTemplates = ( existingTemplates || [] ).reduce(\n\t\t\t\t\t( _accumulator, existingTemplate ) => {\n\t\t\t\t\t\tconst _prefix = `${ prefix }-`;\n\t\t\t\t\t\tif ( existingTemplate.slug.startsWith( _prefix ) ) {\n\t\t\t\t\t\t\t_accumulator.push(\n\t\t\t\t\t\t\t\texistingTemplate.slug.substring(\n\t\t\t\t\t\t\t\t\t_prefix.length\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\treturn _accumulator;\n\t\t\t\t\t},\n\t\t\t\t\t[]\n\t\t\t\t);\n\t\t\t\tif ( slugsWithTemplates.length ) {\n\t\t\t\t\taccumulator[ slug ] = slugsWithTemplates;\n\t\t\t\t}\n\t\t\t\treturn accumulator;\n\t\t\t},\n\t\t\t{}\n\t\t);\n\t}, [ templatePrefixes, existingTemplates ] );\n\treturn existingSlugs;\n};\n\n/**\n * Helper hook that finds the existing records with an associated template,\n * as they need to be excluded from the template suggestions.\n *\n * @param {string} entityName The entity's name.\n * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.\n * @param {Record<string,Object>} additionalQueryParameters An object with the entity's slug as key and additional query parameters as value.\n * @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the existing records as value.\n */\nconst useTemplatesToExclude = (\n\tentityName,\n\ttemplatePrefixes,\n\tadditionalQueryParameters = {}\n) => {\n\tconst slugsToExcludePerEntity =\n\t\tuseExistingTemplateSlugs( templatePrefixes );\n\tconst recordsToExcludePerEntity = useSelect(\n\t\t( select ) => {\n\t\t\treturn Object.entries( slugsToExcludePerEntity || {} ).reduce(\n\t\t\t\t( accumulator, [ slug, slugsWithTemplates ] ) => {\n\t\t\t\t\tconst entitiesWithTemplates = select(\n\t\t\t\t\t\tcoreStore\n\t\t\t\t\t).getEntityRecords( entityName, slug, {\n\t\t\t\t\t\t_fields: 'id',\n\t\t\t\t\t\tcontext: 'view',\n\t\t\t\t\t\tslug: slugsWithTemplates,\n\t\t\t\t\t\t...additionalQueryParameters[ slug ],\n\t\t\t\t\t} );\n\t\t\t\t\tif ( entitiesWithTemplates?.length ) {\n\t\t\t\t\t\taccumulator[ slug ] = entitiesWithTemplates;\n\t\t\t\t\t}\n\t\t\t\t\treturn accumulator;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\t\t},\n\t\t[ slugsToExcludePerEntity ]\n\t);\n\treturn recordsToExcludePerEntity;\n};\n\n/**\n * Helper hook that returns information about an entity having\n * records that we can create a specific template for.\n *\n * For example we can search for `terms` in `taxonomy` entity or\n * `posts` in `postType` entity.\n *\n * First we need to find the existing records with an associated template,\n * to query afterwards for any remaining record, by excluding them.\n *\n * @param {string} entityName The entity's name.\n * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.\n * @param {Record<string,Object>} additionalQueryParameters An object with the entity's slug as key and additional query parameters as value.\n * @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the EntitiesInfo as value.\n */\nconst useEntitiesInfo = (\n\tentityName,\n\ttemplatePrefixes,\n\tadditionalQueryParameters = {}\n) => {\n\tconst recordsToExcludePerEntity = useTemplatesToExclude(\n\t\tentityName,\n\t\ttemplatePrefixes,\n\t\tadditionalQueryParameters\n\t);\n\tconst entitiesInfo = useSelect(\n\t\t( select ) => {\n\t\t\treturn Object.keys( templatePrefixes || {} ).reduce(\n\t\t\t\t( accumulator, slug ) => {\n\t\t\t\t\tconst existingEntitiesIds =\n\t\t\t\t\t\trecordsToExcludePerEntity?.[ slug ]?.map(\n\t\t\t\t\t\t\t( { id } ) => id\n\t\t\t\t\t\t) || [];\n\t\t\t\t\taccumulator[ slug ] = {\n\t\t\t\t\t\thasEntities: !! select( coreStore ).getEntityRecords(\n\t\t\t\t\t\t\tentityName,\n\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tper_page: 1,\n\t\t\t\t\t\t\t\t_fields: 'id',\n\t\t\t\t\t\t\t\tcontext: 'view',\n\t\t\t\t\t\t\t\texclude: existingEntitiesIds,\n\t\t\t\t\t\t\t\t...additionalQueryParameters[ slug ],\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t)?.length,\n\t\t\t\t\t\texistingEntitiesIds,\n\t\t\t\t\t};\n\t\t\t\t\treturn accumulator;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\t\t},\n\t\t[ templatePrefixes, recordsToExcludePerEntity ]\n\t);\n\treturn entitiesInfo;\n};\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/utils.js"],"names":["mapToIHasNameAndId","entities","path","map","entity","name","useExistingTemplates","select","coreStore","getEntityRecords","per_page","useDefaultTemplateTypes","editorStore","__experimentalGetDefaultTemplateTypes","usePublicPostTypes","postTypes","getPostTypes","excludedPostTypes","filter","viewable","slug","includes","usePublicTaxonomies","taxonomies","getTaxonomies","visibility","publicly_queryable","usePostTypeNeedsUniqueIdentifier","publicPostTypes","postTypeLabels","reduce","accumulator","labels","singularName","singular_name","toLowerCase","usePostTypeArchiveMenuItems","postTypesWithArchives","postType","has_archive","existingTemplates","needsUniqueIdentifier","some","existingTemplate","title","description","icon","startsWith","slice","archive","templatePrefix","usePostTypeMenuItems","onClickMenuItem","defaultTemplateTypes","templatePrefixes","suffix","postTypesInfo","useEntitiesInfo","existingTemplateSlugs","menuItems","generalTemplateSlug","defaultTemplateType","find","_slug","hasGeneralTemplate","_needsUniqueIdentifier","menuItemTitle","menuItem","post","hasEntities","onClick","template","type","config","recordNamePath","queryArgs","search","_fields","orderBy","exclude","existingEntitiesIds","getSpecificTemplate","suggestion","push","postTypesMenuItems","key","defaultPostTypesMenuItems","useTaxonomiesMenuItems","publicTaxonomies","taxonomyLabels","taxonomiesInfo","taxonomy","blockMeta","taxonomiesMenuItems","defaultTaxonomiesMenuItems","useAuthorNeedsUniqueIndentifier","authors","getUsers","who","authorsCountByName","authorsCount","USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX","user","USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS","useAuthorMenuItem","authorInfo","authorNeedsUniqueId","authorMenuItem","needsUniqueId","search_items","not_found","all_items","useExistingTemplateSlugs","existingSlugs","Object","entries","prefix","slugsWithTemplates","_accumulator","_prefix","substring","length","useTemplatesToExclude","entityName","additionalQueryParameters","slugsToExcludePerEntity","recordsToExcludePerEntity","entitiesWithTemplates","context","entitiesInfo","keys","id"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAdA;AACA;AACA;;AAGA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAG,CAAEC,QAAF,EAAYC,IAAZ,KAAsB;AACvD,SAAO,CAAED,QAAQ,IAAI,EAAd,EAAmBE,GAAnB,CAA0BC,MAAF,KAAgB,EAC9C,GAAGA,MAD2C;AAE9CC,IAAAA,IAAI,EAAE,kCAAgB,iBAAKD,MAAL,EAAaF,IAAb,CAAhB;AAFwC,GAAhB,CAAxB,CAAP;AAIA,CALM;AAOP;AACA;AACA;AACA;AACA;;;;;AAEO,MAAMI,oBAAoB,GAAG,MAAM;AACzC,SAAO,qBACJC,MAAF,IACCA,MAAM,CAAEC,eAAF,CAAN,CAAoB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BAFuB,EAInB;AAAA,MADJsE,yBACI,uEADwB,EACxB;AACJ,QAAME,yBAAyB,GAAGJ,qBAAqB,CACtDC,UADsD,EAEtDrE,gBAFsD,EAGtDsE,yBAHsD,CAAvD;AAKA,QAAMK,YAAY,GAAG,qBAClB1H,MAAF,IAAc;AACb,WAAO2G,MAAM,CAACgB,IAAP,CAAa5E,gBAAgB,IAAI,EAAjC,EAAsCxB,MAAtC,CACN,CAAEC,WAAF,EAAeX,IAAf,KAAyB;AAAA;;AACxB,YAAM4D,mBAAmB,GACxB,CAAA8C,yBAAyB,SAAzB,IAAAA,yBAAyB,WAAzB,qCAAAA,yBAAyB,CAAI1G,IAAJ,CAAzB,gFAAqCjB,GAArC,CACC;AAAA,YAAE;AAAEgI,UAAAA;AAAF,SAAF;AAAA,eAAcA,EAAd;AAAA,OADD,MAEK,EAHN;AAIApG,MAAAA,WAAW,CAAEX,IAAF,CAAX,GAAsB;AACrBiD,QAAAA,WAAW,EAAE,CAAC,2BAAE9D,MAAM,CAAEC,eAAF,CAAN,CAAoBC,gBAApB,CACfkH,UADe,EAEfvG,IAFe,EAGf;AACCV,UAAAA,QAAQ,EAAE,CADX;AAECmE,UAAAA,OAAO,EAAE,IAFV;AAGCmD,UAAAA,OAAO,EAAE,MAHV;AAICjD,UAAAA,OAAO,EAAEC,mBAJV;AAKC,aAAG4C,yBAAyB,CAAExG,IAAF;AAL7B,SAHe,CAAF,kDAAE,sBAUbqG,MAVW,CADO;AAYrBzC,QAAAA;AAZqB,OAAtB;AAcA,aAAOjD,WAAP;AACA,KArBK,EAsBN,EAtBM,CAAP;AAwBA,GA1BmB,EA2BpB,CAAEuB,gBAAF,EAAoBwE,yBAApB,CA3BoB,CAArB;AA6BA,SAAOG,YAAP;AACA,CAxCD","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useMemo, useCallback } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { blockMeta, post, archive } from '@wordpress/icons';\n\n/**\n * @typedef IHasNameAndId\n * @property {string|number} id The entity's id.\n * @property {string} name The entity's name.\n */\n\n/**\n * Helper util to map records to add a `name` prop from a\n * provided path, in order to handle all entities in the same\n * fashion(implementing`IHasNameAndId` interface).\n *\n * @param {Object[]} entities The array of entities.\n * @param {string} path The path to map a `name` property from the entity.\n * @return {IHasNameAndId[]} An array of enitities that now implement the `IHasNameAndId` interface.\n */\nexport const mapToIHasNameAndId = ( entities, path ) => {\n\treturn ( entities || [] ).map( ( entity ) => ( {\n\t\t...entity,\n\t\tname: decodeEntities( get( entity, path ) ),\n\t} ) );\n};\n\n/**\n * @typedef {Object} EntitiesInfo\n * @property {boolean} hasEntities If an entity has available records(posts, terms, etc..).\n * @property {number[]} existingEntitiesIds An array of the existing entities ids.\n */\n\nexport const useExistingTemplates = () => {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\tper_page: -1,\n\t\t\t} ),\n\t\t[]\n\t);\n};\n\nexport const useDefaultTemplateTypes = () => {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( editorStore ).__experimentalGetDefaultTemplateTypes(),\n\t\t[]\n\t);\n};\n\nconst usePublicPostTypes = () => {\n\tconst postTypes = useSelect(\n\t\t( select ) => select( coreStore ).getPostTypes( { per_page: -1 } ),\n\t\t[]\n\t);\n\treturn useMemo( () => {\n\t\tconst excludedPostTypes = [ 'attachment' ];\n\t\treturn postTypes?.filter(\n\t\t\t( { viewable, slug } ) =>\n\t\t\t\tviewable && ! excludedPostTypes.includes( slug )\n\t\t);\n\t}, [ postTypes ] );\n};\n\nconst usePublicTaxonomies = () => {\n\tconst taxonomies = useSelect(\n\t\t( select ) => select( coreStore ).getTaxonomies( { per_page: -1 } ),\n\t\t[]\n\t);\n\treturn useMemo( () => {\n\t\treturn taxonomies?.filter(\n\t\t\t( { visibility } ) => visibility?.publicly_queryable\n\t\t);\n\t}, [ taxonomies ] );\n};\n\nfunction usePostTypeNeedsUniqueIdentifier( publicPostTypes ) {\n\tconst postTypeLabels = useMemo( () =>\n\t\tpublicPostTypes?.reduce( ( accumulator, { labels } ) => {\n\t\t\tconst singularName = labels.singular_name.toLowerCase();\n\t\t\taccumulator[ singularName ] =\n\t\t\t\t( accumulator[ singularName ] || 0 ) + 1;\n\t\t\treturn accumulator;\n\t\t}, {} )\n\t);\n\treturn useCallback(\n\t\t( { labels, slug } ) => {\n\t\t\tconst singularName = labels.singular_name.toLowerCase();\n\t\t\treturn postTypeLabels[ singularName ] > 1 && singularName !== slug;\n\t\t},\n\t\t[ postTypeLabels ]\n\t);\n}\n\nexport function usePostTypeArchiveMenuItems() {\n\tconst publicPostTypes = usePublicPostTypes();\n\tconst postTypesWithArchives = useMemo(\n\t\t() => publicPostTypes?.filter( ( postType ) => postType.has_archive ),\n\t\t[ publicPostTypes ]\n\t);\n\tconst existingTemplates = useExistingTemplates();\n\tconst needsUniqueIdentifier = usePostTypeNeedsUniqueIdentifier(\n\t\tpostTypesWithArchives\n\t);\n\treturn useMemo(\n\t\t() =>\n\t\t\tpostTypesWithArchives\n\t\t\t\t?.filter(\n\t\t\t\t\t( postType ) =>\n\t\t\t\t\t\t! ( existingTemplates || [] ).some(\n\t\t\t\t\t\t\t( existingTemplate ) =>\n\t\t\t\t\t\t\t\texistingTemplate.slug ===\n\t\t\t\t\t\t\t\t'archive-' + postType.slug\n\t\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t.map( ( postType ) => {\n\t\t\t\t\tlet title;\n\t\t\t\t\tif ( needsUniqueIdentifier( postType ) ) {\n\t\t\t\t\t\ttitle = sprintf(\n\t\t\t\t\t\t\t// translators: %1s: Name of the post type e.g: \"Post\"; %2s: Slug of the post type e.g: \"book\".\n\t\t\t\t\t\t\t__( 'Archive: %1$s (%2$s)' ),\n\t\t\t\t\t\t\tpostType.labels.singular_name,\n\t\t\t\t\t\t\tpostType.slug\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttitle = sprintf(\n\t\t\t\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t\t\t\t__( 'Archive: %s' ),\n\t\t\t\t\t\t\tpostType.labels.singular_name\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\tslug: 'archive-' + postType.slug,\n\t\t\t\t\t\tdescription: sprintf(\n\t\t\t\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t'Displays an archive with the latests posts of type: %s.'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tpostType.labels.singular_name\n\t\t\t\t\t\t),\n\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t// `icon` is the `menu_icon` property of a post type. We\n\t\t\t\t\t\t// only handle `dashicons` for now, even if the `menu_icon`\n\t\t\t\t\t\t// also supports urls and svg as values.\n\t\t\t\t\t\ticon: postType.icon?.startsWith( 'dashicons-' )\n\t\t\t\t\t\t\t? postType.icon.slice( 10 )\n\t\t\t\t\t\t\t: archive,\n\t\t\t\t\t\ttemplatePrefix: 'archive',\n\t\t\t\t\t};\n\t\t\t\t} ) || [],\n\t\t[ postTypesWithArchives, existingTemplates, needsUniqueIdentifier ]\n\t);\n}\n\nexport const usePostTypeMenuItems = ( onClickMenuItem ) => {\n\tconst publicPostTypes = usePublicPostTypes();\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst needsUniqueIdentifier =\n\t\tusePostTypeNeedsUniqueIdentifier( publicPostTypes );\n\t// `page`is a special case in template hierarchy.\n\tconst templatePrefixes = useMemo(\n\t\t() =>\n\t\t\tpublicPostTypes?.reduce( ( accumulator, { slug } ) => {\n\t\t\t\tlet suffix = slug;\n\t\t\t\tif ( slug !== 'page' ) {\n\t\t\t\t\tsuffix = `single-${ suffix }`;\n\t\t\t\t}\n\t\t\t\taccumulator[ slug ] = suffix;\n\t\t\t\treturn accumulator;\n\t\t\t}, {} ),\n\t\t[ publicPostTypes ]\n\t);\n\tconst postTypesInfo = useEntitiesInfo( 'postType', templatePrefixes );\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst menuItems = ( publicPostTypes || [] ).reduce(\n\t\t( accumulator, postType ) => {\n\t\t\tconst { slug, labels, icon } = postType;\n\t\t\t// We need to check if the general template is part of the\n\t\t\t// defaultTemplateTypes. If it is, just use that info and\n\t\t\t// augment it with the specific template functionality.\n\t\t\tconst generalTemplateSlug = templatePrefixes[ slug ];\n\t\t\tconst defaultTemplateType = defaultTemplateTypes?.find(\n\t\t\t\t( { slug: _slug } ) => _slug === generalTemplateSlug\n\t\t\t);\n\t\t\tconst hasGeneralTemplate =\n\t\t\t\texistingTemplateSlugs?.includes( generalTemplateSlug );\n\t\t\tconst _needsUniqueIdentifier = needsUniqueIdentifier( postType );\n\t\t\tlet menuItemTitle = sprintf(\n\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t__( 'Single item: %s' ),\n\t\t\t\tlabels.singular_name\n\t\t\t);\n\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\tmenuItemTitle = sprintf(\n\t\t\t\t\t// translators: %1s: Name of the post type e.g: \"Post\"; %2s: Slug of the post type e.g: \"book\".\n\t\t\t\t\t__( 'Single item: %1$s (%2$s)' ),\n\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\tslug\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst menuItem = defaultTemplateType\n\t\t\t\t? {\n\t\t\t\t\t\t...defaultTemplateType,\n\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t }\n\t\t\t\t: {\n\t\t\t\t\t\tslug: generalTemplateSlug,\n\t\t\t\t\t\ttitle: menuItemTitle,\n\t\t\t\t\t\tdescription: sprintf(\n\t\t\t\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t\t\t\t__( 'Displays a single item: %s.' ),\n\t\t\t\t\t\t\tlabels.singular_name\n\t\t\t\t\t\t),\n\t\t\t\t\t\t// `icon` is the `menu_icon` property of a post type. We\n\t\t\t\t\t\t// only handle `dashicons` for now, even if the `menu_icon`\n\t\t\t\t\t\t// also supports urls and svg as values.\n\t\t\t\t\t\ticon: icon?.startsWith( 'dashicons-' )\n\t\t\t\t\t\t\t? icon.slice( 10 )\n\t\t\t\t\t\t\t: post,\n\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t };\n\t\t\tconst hasEntities = postTypesInfo?.[ slug ]?.hasEntities;\n\t\t\t// We have a different template creation flow only if they have entities.\n\t\t\tif ( hasEntities ) {\n\t\t\t\tmenuItem.onClick = ( template ) => {\n\t\t\t\t\tonClickMenuItem( {\n\t\t\t\t\t\ttype: 'postType',\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\trecordNamePath: 'title.rendered',\n\t\t\t\t\t\t\tqueryArgs: ( { search } ) => {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t_fields: 'id,title,slug,link',\n\t\t\t\t\t\t\t\t\torderBy: search ? 'relevance' : 'modified',\n\t\t\t\t\t\t\t\t\texclude:\n\t\t\t\t\t\t\t\t\t\tpostTypesInfo[ slug ]\n\t\t\t\t\t\t\t\t\t\t\t.existingEntitiesIds,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tgetSpecificTemplate: ( suggestion ) => {\n\t\t\t\t\t\t\t\tlet title = sprintf(\n\t\t\t\t\t\t\t\t\t// translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the singular name of a post type and %2$s is the name of the post, e.g. \"Page: Hello\".\n\t\t\t\t\t\t\t\t\t__( '%1$s: %2$s' ),\n\t\t\t\t\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tconst description = sprintf(\n\t\t\t\t\t\t\t\t\t// translators: Represents the description of a user's custom template in the Site Editor, e.g. \"Template for Page: Hello\"\n\t\t\t\t\t\t\t\t\t__( 'Template for %1$s' ),\n\t\t\t\t\t\t\t\t\ttitle\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\t\t\t\t\t\ttitle = sprintf(\n\t\t\t\t\t\t\t\t\t\t// translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the template title and %2$s is the slug of the post type, e.g. \"Project: Hello (project_type)\"\n\t\t\t\t\t\t\t\t\t\t__( '%1$s (%2$s)' ),\n\t\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\t\tslug\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\treturn {\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: `${ templatePrefixes[ slug ] }-${ suggestion.slug }`,\n\t\t\t\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\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\tlabels,\n\t\t\t\t\t\thasGeneralTemplate,\n\t\t\t\t\t\ttemplate,\n\t\t\t\t\t} );\n\t\t\t\t};\n\t\t\t}\n\t\t\t// We don't need to add the menu item if there are no\n\t\t\t// entities and the general template exists.\n\t\t\tif ( ! hasGeneralTemplate || hasEntities ) {\n\t\t\t\taccumulator.push( menuItem );\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t},\n\t\t[]\n\t);\n\t// Split menu items into two groups: one for the default post types\n\t// and one for the rest.\n\tconst postTypesMenuItems = useMemo(\n\t\t() =>\n\t\t\tmenuItems.reduce(\n\t\t\t\t( accumulator, postType ) => {\n\t\t\t\t\tconst { slug } = postType;\n\t\t\t\t\tlet key = 'postTypesMenuItems';\n\t\t\t\t\tif ( slug === 'page' ) {\n\t\t\t\t\t\tkey = 'defaultPostTypesMenuItems';\n\t\t\t\t\t}\n\t\t\t\t\taccumulator[ key ].push( postType );\n\t\t\t\t\treturn accumulator;\n\t\t\t\t},\n\t\t\t\t{ defaultPostTypesMenuItems: [], postTypesMenuItems: [] }\n\t\t\t),\n\t\t[ menuItems ]\n\t);\n\treturn postTypesMenuItems;\n};\n\nexport const useTaxonomiesMenuItems = ( onClickMenuItem ) => {\n\tconst publicTaxonomies = usePublicTaxonomies();\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\t// `category` and `post_tag` are special cases in template hierarchy.\n\tconst templatePrefixes = useMemo(\n\t\t() =>\n\t\t\tpublicTaxonomies?.reduce( ( accumulator, { slug } ) => {\n\t\t\t\tlet suffix = slug;\n\t\t\t\tif ( ! [ 'category', 'post_tag' ].includes( slug ) ) {\n\t\t\t\t\tsuffix = `taxonomy-${ suffix }`;\n\t\t\t\t}\n\t\t\t\tif ( slug === 'post_tag' ) {\n\t\t\t\t\tsuffix = `tag`;\n\t\t\t\t}\n\t\t\t\taccumulator[ slug ] = suffix;\n\t\t\t\treturn accumulator;\n\t\t\t}, {} ),\n\t\t[ publicTaxonomies ]\n\t);\n\t// We need to keep track of naming conflicts. If a conflict\n\t// occurs, we need to add slug.\n\tconst taxonomyLabels = publicTaxonomies?.reduce(\n\t\t( accumulator, { labels } ) => {\n\t\t\tconst singularName = labels.singular_name.toLowerCase();\n\t\t\taccumulator[ singularName ] =\n\t\t\t\t( accumulator[ singularName ] || 0 ) + 1;\n\t\t\treturn accumulator;\n\t\t},\n\t\t{}\n\t);\n\tconst needsUniqueIdentifier = ( labels, slug ) => {\n\t\tif ( [ 'category', 'post_tag' ].includes( slug ) ) {\n\t\t\treturn false;\n\t\t}\n\t\tconst singularName = labels.singular_name.toLowerCase();\n\t\treturn taxonomyLabels[ singularName ] > 1 && singularName !== slug;\n\t};\n\tconst taxonomiesInfo = useEntitiesInfo( 'taxonomy', templatePrefixes );\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst menuItems = ( publicTaxonomies || [] ).reduce(\n\t\t( accumulator, taxonomy ) => {\n\t\t\tconst { slug, labels } = taxonomy;\n\t\t\t// We need to check if the general template is part of the\n\t\t\t// defaultTemplateTypes. If it is, just use that info and\n\t\t\t// augment it with the specific template functionality.\n\t\t\tconst generalTemplateSlug = templatePrefixes[ slug ];\n\t\t\tconst defaultTemplateType = defaultTemplateTypes?.find(\n\t\t\t\t( { slug: _slug } ) => _slug === generalTemplateSlug\n\t\t\t);\n\t\t\tconst hasGeneralTemplate =\n\t\t\t\texistingTemplateSlugs?.includes( generalTemplateSlug );\n\t\t\tconst _needsUniqueIdentifier = needsUniqueIdentifier(\n\t\t\t\tlabels,\n\t\t\t\tslug\n\t\t\t);\n\t\t\tlet menuItemTitle = labels.singular_name;\n\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\tmenuItemTitle = sprintf(\n\t\t\t\t\t// translators: %1s: Name of the taxonomy e.g: \"Category\"; %2s: Slug of the taxonomy e.g: \"product_cat\".\n\t\t\t\t\t__( '%1$s (%2$s)' ),\n\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\tslug\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst menuItem = defaultTemplateType\n\t\t\t\t? {\n\t\t\t\t\t\t...defaultTemplateType,\n\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t }\n\t\t\t\t: {\n\t\t\t\t\t\tslug: generalTemplateSlug,\n\t\t\t\t\t\ttitle: menuItemTitle,\n\t\t\t\t\t\tdescription: sprintf(\n\t\t\t\t\t\t\t// translators: %s: Name of the taxonomy e.g: \"Product Categories\".\n\t\t\t\t\t\t\t__( 'Displays taxonomy: %s.' ),\n\t\t\t\t\t\t\tlabels.singular_name\n\t\t\t\t\t\t),\n\t\t\t\t\t\ticon: blockMeta,\n\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t };\n\t\t\tconst hasEntities = taxonomiesInfo?.[ slug ]?.hasEntities;\n\t\t\t// We have a different template creation flow only if they have entities.\n\t\t\tif ( hasEntities ) {\n\t\t\t\tmenuItem.onClick = ( template ) => {\n\t\t\t\t\tonClickMenuItem( {\n\t\t\t\t\t\ttype: 'taxonomy',\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\tqueryArgs: ( { search } ) => {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t_fields: 'id,name,slug,link',\n\t\t\t\t\t\t\t\t\torderBy: search ? 'name' : 'count',\n\t\t\t\t\t\t\t\t\texclude:\n\t\t\t\t\t\t\t\t\t\ttaxonomiesInfo[ slug ]\n\t\t\t\t\t\t\t\t\t\t\t.existingEntitiesIds,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tgetSpecificTemplate: ( suggestion ) => {\n\t\t\t\t\t\t\t\tlet title = sprintf(\n\t\t\t\t\t\t\t\t\t// translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the singular name of a taxonomy and %2$s is the name of the term, e.g. \"Category: shoes\".\n\t\t\t\t\t\t\t\t\t__( '%1$s: %2$s' ),\n\t\t\t\t\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tconst description = sprintf(\n\t\t\t\t\t\t\t\t\t// translators: Represents the description of a user's custom template in the Site Editor, e.g. \"Template for Category: shoes\"\n\t\t\t\t\t\t\t\t\t__( 'Template for %1$s' ),\n\t\t\t\t\t\t\t\t\ttitle\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\t\t\t\t\t\ttitle = sprintf(\n\t\t\t\t\t\t\t\t\t\t// translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the template title and %2$s is the slug of the taxonomy, e.g. \"Category: shoes (product_tag)\"\n\t\t\t\t\t\t\t\t\t\t__( '%1$s (%2$s)' ),\n\t\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\t\tslug\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\treturn {\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: `${ templatePrefixes[ slug ] }-${ suggestion.slug }`,\n\t\t\t\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\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\tlabels,\n\t\t\t\t\t\thasGeneralTemplate,\n\t\t\t\t\t\ttemplate,\n\t\t\t\t\t} );\n\t\t\t\t};\n\t\t\t}\n\t\t\t// We don't need to add the menu item if there are no\n\t\t\t// entities and the general template exists.\n\t\t\tif ( ! hasGeneralTemplate || hasEntities ) {\n\t\t\t\taccumulator.push( menuItem );\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t},\n\t\t[]\n\t);\n\t// Split menu items into two groups: one for the default taxonomies\n\t// and one for the rest.\n\tconst taxonomiesMenuItems = useMemo(\n\t\t() =>\n\t\t\tmenuItems.reduce(\n\t\t\t\t( accumulator, taxonomy ) => {\n\t\t\t\t\tconst { slug } = taxonomy;\n\t\t\t\t\tlet key = 'taxonomiesMenuItems';\n\t\t\t\t\tif ( [ 'category', 'tag' ].includes( slug ) ) {\n\t\t\t\t\t\tkey = 'defaultTaxonomiesMenuItems';\n\t\t\t\t\t}\n\t\t\t\t\taccumulator[ key ].push( taxonomy );\n\t\t\t\t\treturn accumulator;\n\t\t\t\t},\n\t\t\t\t{ defaultTaxonomiesMenuItems: [], taxonomiesMenuItems: [] }\n\t\t\t),\n\t\t[ menuItems ]\n\t);\n\treturn taxonomiesMenuItems;\n};\n\nfunction useAuthorNeedsUniqueIndentifier() {\n\tconst authors = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getUsers( { who: 'authors', per_page: -1 } ),\n\t\t[]\n\t);\n\tconst authorsCountByName = useMemo( () => {\n\t\treturn ( authors || [] ).reduce( ( authorsCount, { name } ) => {\n\t\t\tauthorsCount[ name ] = ( authorsCount[ name ] || 0 ) + 1;\n\t\t\treturn authorsCount;\n\t\t}, {} );\n\t}, [ authors ] );\n\treturn useCallback(\n\t\t( name ) => {\n\t\t\treturn authorsCountByName[ name ] > 1;\n\t\t},\n\t\t[ authorsCountByName ]\n\t);\n}\n\nconst USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX = { user: 'author' };\nconst USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS = { user: { who: 'authors' } };\nexport function useAuthorMenuItem( onClickMenuItem ) {\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst authorInfo = useEntitiesInfo(\n\t\t'root',\n\t\tUSE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX,\n\t\tUSE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS\n\t);\n\tconst authorNeedsUniqueId = useAuthorNeedsUniqueIndentifier();\n\tlet authorMenuItem = defaultTemplateTypes?.find(\n\t\t( { slug } ) => slug === 'author'\n\t);\n\tif ( ! authorMenuItem ) {\n\t\tauthorMenuItem = {\n\t\t\tdescription: __(\n\t\t\t\t'Displays latest posts written by a single author.'\n\t\t\t),\n\t\t\tslug: 'author',\n\t\t\ttitle: 'Author',\n\t\t};\n\t}\n\tconst hasGeneralTemplate = !! existingTemplates?.find(\n\t\t( { slug } ) => slug === 'author'\n\t);\n\tif ( authorInfo.user?.hasEntities ) {\n\t\tauthorMenuItem = { ...authorMenuItem, templatePrefix: 'author' };\n\t\tauthorMenuItem.onClick = ( template ) => {\n\t\t\tonClickMenuItem( {\n\t\t\t\ttype: 'root',\n\t\t\t\tslug: 'user',\n\t\t\t\tconfig: {\n\t\t\t\t\tqueryArgs: ( { search } ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t_fields: 'id,name,slug,link',\n\t\t\t\t\t\t\torderBy: search ? 'name' : 'registered_date',\n\t\t\t\t\t\t\texclude: authorInfo.user.existingEntitiesIds,\n\t\t\t\t\t\t\twho: 'authors',\n\t\t\t\t\t\t};\n\t\t\t\t\t},\n\t\t\t\t\tgetSpecificTemplate: ( suggestion ) => {\n\t\t\t\t\t\tconst needsUniqueId = authorNeedsUniqueId(\n\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst title = needsUniqueId\n\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t// translators: %1$s: Represents the name of an author e.g: \"Jorge\", %2$s: Represents the slug of an author e.g: \"author-jorge-slug\".\n\t\t\t\t\t\t\t\t\t__( 'Author: %1$s (%2$s)' ),\n\t\t\t\t\t\t\t\t\tsuggestion.name,\n\t\t\t\t\t\t\t\t\tsuggestion.slug\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t\t// translators: %s: Represents the name of an author e.g: \"Jorge\".\n\t\t\t\t\t\t\t\t\t__( 'Author: %s' ),\n\t\t\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t\t );\n\t\t\t\t\t\tconst description = sprintf(\n\t\t\t\t\t\t\t// translators: %s: Represents the name of an author e.g: \"Jorge\".\n\t\t\t\t\t\t\t__( 'Template for Author: %s' ),\n\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\tslug: `author-${ suggestion.slug }`,\n\t\t\t\t\t\t\ttemplatePrefix: 'author',\n\t\t\t\t\t\t};\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tlabels: {\n\t\t\t\t\tsingular_name: __( 'Author' ),\n\t\t\t\t\tsearch_items: __( 'Search Authors' ),\n\t\t\t\t\tnot_found: __( 'No authors found.' ),\n\t\t\t\t\tall_items: __( 'All Authors' ),\n\t\t\t\t},\n\t\t\t\thasGeneralTemplate,\n\t\t\t\ttemplate,\n\t\t\t} );\n\t\t};\n\t}\n\tif ( ! hasGeneralTemplate || authorInfo.user?.hasEntities ) {\n\t\treturn authorMenuItem;\n\t}\n}\n\n/**\n * Helper hook that filters all the existing templates by the given\n * object with the entity's slug as key and the template prefix as value.\n *\n * Example:\n * `existingTemplates` is: [ { slug: 'tag-apple' }, { slug: 'page-about' }, { slug: 'tag' } ]\n * `templatePrefixes` is: { post_tag: 'tag' }\n * It will return: { post_tag: ['apple'] }\n *\n * Note: We append the `-` to the given template prefix in this function for our checks.\n *\n * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.\n * @return {Record<string,string[]>} An object with the entity's slug as key and an array with the existing template slugs as value.\n */\nconst useExistingTemplateSlugs = ( templatePrefixes ) => {\n\tconst existingTemplates = useExistingTemplates();\n\tconst existingSlugs = useMemo( () => {\n\t\treturn Object.entries( templatePrefixes || {} ).reduce(\n\t\t\t( accumulator, [ slug, prefix ] ) => {\n\t\t\t\tconst slugsWithTemplates = ( existingTemplates || [] ).reduce(\n\t\t\t\t\t( _accumulator, existingTemplate ) => {\n\t\t\t\t\t\tconst _prefix = `${ prefix }-`;\n\t\t\t\t\t\tif ( existingTemplate.slug.startsWith( _prefix ) ) {\n\t\t\t\t\t\t\t_accumulator.push(\n\t\t\t\t\t\t\t\texistingTemplate.slug.substring(\n\t\t\t\t\t\t\t\t\t_prefix.length\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\treturn _accumulator;\n\t\t\t\t\t},\n\t\t\t\t\t[]\n\t\t\t\t);\n\t\t\t\tif ( slugsWithTemplates.length ) {\n\t\t\t\t\taccumulator[ slug ] = slugsWithTemplates;\n\t\t\t\t}\n\t\t\t\treturn accumulator;\n\t\t\t},\n\t\t\t{}\n\t\t);\n\t}, [ templatePrefixes, existingTemplates ] );\n\treturn existingSlugs;\n};\n\n/**\n * Helper hook that finds the existing records with an associated template,\n * as they need to be excluded from the template suggestions.\n *\n * @param {string} entityName The entity's name.\n * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.\n * @param {Record<string,Object>} additionalQueryParameters An object with the entity's slug as key and additional query parameters as value.\n * @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the existing records as value.\n */\nconst useTemplatesToExclude = (\n\tentityName,\n\ttemplatePrefixes,\n\tadditionalQueryParameters = {}\n) => {\n\tconst slugsToExcludePerEntity =\n\t\tuseExistingTemplateSlugs( templatePrefixes );\n\tconst recordsToExcludePerEntity = useSelect(\n\t\t( select ) => {\n\t\t\treturn Object.entries( slugsToExcludePerEntity || {} ).reduce(\n\t\t\t\t( accumulator, [ slug, slugsWithTemplates ] ) => {\n\t\t\t\t\tconst entitiesWithTemplates = select(\n\t\t\t\t\t\tcoreStore\n\t\t\t\t\t).getEntityRecords( entityName, slug, {\n\t\t\t\t\t\t_fields: 'id',\n\t\t\t\t\t\tcontext: 'view',\n\t\t\t\t\t\tslug: slugsWithTemplates,\n\t\t\t\t\t\t...additionalQueryParameters[ slug ],\n\t\t\t\t\t} );\n\t\t\t\t\tif ( entitiesWithTemplates?.length ) {\n\t\t\t\t\t\taccumulator[ slug ] = entitiesWithTemplates;\n\t\t\t\t\t}\n\t\t\t\t\treturn accumulator;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\t\t},\n\t\t[ slugsToExcludePerEntity ]\n\t);\n\treturn recordsToExcludePerEntity;\n};\n\n/**\n * Helper hook that returns information about an entity having\n * records that we can create a specific template for.\n *\n * For example we can search for `terms` in `taxonomy` entity or\n * `posts` in `postType` entity.\n *\n * First we need to find the existing records with an associated template,\n * to query afterwards for any remaining record, by excluding them.\n *\n * @param {string} entityName The entity's name.\n * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.\n * @param {Record<string,Object>} additionalQueryParameters An object with the entity's slug as key and additional query parameters as value.\n * @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the EntitiesInfo as value.\n */\nconst useEntitiesInfo = (\n\tentityName,\n\ttemplatePrefixes,\n\tadditionalQueryParameters = {}\n) => {\n\tconst recordsToExcludePerEntity = useTemplatesToExclude(\n\t\tentityName,\n\t\ttemplatePrefixes,\n\t\tadditionalQueryParameters\n\t);\n\tconst entitiesInfo = useSelect(\n\t\t( select ) => {\n\t\t\treturn Object.keys( templatePrefixes || {} ).reduce(\n\t\t\t\t( accumulator, slug ) => {\n\t\t\t\t\tconst existingEntitiesIds =\n\t\t\t\t\t\trecordsToExcludePerEntity?.[ slug ]?.map(\n\t\t\t\t\t\t\t( { id } ) => id\n\t\t\t\t\t\t) || [];\n\t\t\t\t\taccumulator[ slug ] = {\n\t\t\t\t\t\thasEntities: !! select( coreStore ).getEntityRecords(\n\t\t\t\t\t\t\tentityName,\n\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tper_page: 1,\n\t\t\t\t\t\t\t\t_fields: 'id',\n\t\t\t\t\t\t\t\tcontext: 'view',\n\t\t\t\t\t\t\t\texclude: existingEntitiesIds,\n\t\t\t\t\t\t\t\t...additionalQueryParameters[ slug ],\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t)?.length,\n\t\t\t\t\t\texistingEntitiesIds,\n\t\t\t\t\t};\n\t\t\t\t\treturn accumulator;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\t\t},\n\t\t[ templatePrefixes, recordsToExcludePerEntity ]\n\t);\n\treturn entitiesInfo;\n};\n"]}