@wordpress/edit-site 6.30.1-next.a730c9c8c.0 → 6.31.1-next.f56bd8138.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 (77) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/add-new-template/add-custom-template-modal-content.js +3 -2
  3. package/build/components/add-new-template/add-custom-template-modal-content.js.map +1 -1
  4. package/build/components/add-new-template/index.js +1 -5
  5. package/build/components/add-new-template/index.js.map +1 -1
  6. package/build/components/add-new-template/utils.js +26 -87
  7. package/build/components/add-new-template/utils.js.map +1 -1
  8. package/build/components/dataviews-actions/index.js +51 -1
  9. package/build/components/dataviews-actions/index.js.map +1 -1
  10. package/build/components/editor/index.js +1 -1
  11. package/build/components/editor/index.js.map +1 -1
  12. package/build/components/editor/use-resolve-edited-entity.js +42 -14
  13. package/build/components/editor/use-resolve-edited-entity.js.map +1 -1
  14. package/build/components/global-styles/screen-css.js +2 -3
  15. package/build/components/global-styles/screen-css.js.map +1 -1
  16. package/build/components/global-styles/screen-root.js +3 -35
  17. package/build/components/global-styles/screen-root.js.map +1 -1
  18. package/build/components/page-templates/fields.js +65 -5
  19. package/build/components/page-templates/fields.js.map +1 -1
  20. package/build/components/page-templates/hooks.js +1 -1
  21. package/build/components/page-templates/hooks.js.map +1 -1
  22. package/build/components/page-templates/index.js +103 -29
  23. package/build/components/page-templates/index.js.map +1 -1
  24. package/build/components/sidebar-global-styles-wrapper/index.js +45 -13
  25. package/build/components/sidebar-global-styles-wrapper/index.js.map +1 -1
  26. package/build/components/sidebar-navigation-screen-templates-browse/content.js +11 -5
  27. package/build/components/sidebar-navigation-screen-templates-browse/content.js.map +1 -1
  28. package/build/components/site-editor-routes/index.js +1 -1
  29. package/build/components/site-editor-routes/index.js.map +1 -1
  30. package/build/components/site-editor-routes/template-item.js +29 -23
  31. package/build/components/site-editor-routes/template-item.js.map +1 -1
  32. package/build-module/components/add-new-template/add-custom-template-modal-content.js +3 -2
  33. package/build-module/components/add-new-template/add-custom-template-modal-content.js.map +1 -1
  34. package/build-module/components/add-new-template/index.js +2 -6
  35. package/build-module/components/add-new-template/index.js.map +1 -1
  36. package/build-module/components/add-new-template/utils.js +26 -87
  37. package/build-module/components/add-new-template/utils.js.map +1 -1
  38. package/build-module/components/dataviews-actions/index.js +49 -0
  39. package/build-module/components/dataviews-actions/index.js.map +1 -1
  40. package/build-module/components/editor/index.js +1 -1
  41. package/build-module/components/editor/index.js.map +1 -1
  42. package/build-module/components/editor/use-resolve-edited-entity.js +42 -14
  43. package/build-module/components/editor/use-resolve-edited-entity.js.map +1 -1
  44. package/build-module/components/global-styles/screen-css.js +2 -3
  45. package/build-module/components/global-styles/screen-css.js.map +1 -1
  46. package/build-module/components/global-styles/screen-root.js +4 -36
  47. package/build-module/components/global-styles/screen-root.js.map +1 -1
  48. package/build-module/components/page-templates/fields.js +65 -5
  49. package/build-module/components/page-templates/fields.js.map +1 -1
  50. package/build-module/components/page-templates/hooks.js +1 -1
  51. package/build-module/components/page-templates/hooks.js.map +1 -1
  52. package/build-module/components/page-templates/index.js +105 -31
  53. package/build-module/components/page-templates/index.js.map +1 -1
  54. package/build-module/components/sidebar-global-styles-wrapper/index.js +48 -16
  55. package/build-module/components/sidebar-global-styles-wrapper/index.js.map +1 -1
  56. package/build-module/components/sidebar-navigation-screen-templates-browse/content.js +11 -5
  57. package/build-module/components/sidebar-navigation-screen-templates-browse/content.js.map +1 -1
  58. package/build-module/components/site-editor-routes/index.js +2 -2
  59. package/build-module/components/site-editor-routes/index.js.map +1 -1
  60. package/build-module/components/site-editor-routes/template-item.js +28 -22
  61. package/build-module/components/site-editor-routes/template-item.js.map +1 -1
  62. package/package.json +41 -41
  63. package/src/components/add-new-template/add-custom-template-modal-content.js +3 -4
  64. package/src/components/add-new-template/index.js +1 -8
  65. package/src/components/add-new-template/utils.js +36 -121
  66. package/src/components/dataviews-actions/index.js +51 -0
  67. package/src/components/editor/index.js +1 -0
  68. package/src/components/editor/use-resolve-edited-entity.js +54 -7
  69. package/src/components/global-styles/screen-css.js +4 -5
  70. package/src/components/global-styles/screen-root.js +5 -51
  71. package/src/components/page-templates/fields.js +70 -4
  72. package/src/components/page-templates/hooks.js +1 -1
  73. package/src/components/page-templates/index.js +160 -57
  74. package/src/components/sidebar-global-styles-wrapper/index.js +62 -16
  75. package/src/components/sidebar-navigation-screen-templates-browse/content.js +17 -7
  76. package/src/components/site-editor-routes/index.js +2 -1
  77. package/src/components/site-editor-routes/template-item.js +34 -26
@@ -1 +1 @@
1
- {"version":3,"names":["clsx","Button","Modal","__experimentalGrid","Grid","__experimentalText","Text","__experimentalVStack","VStack","Flex","Icon","decodeEntities","useState","memo","useRef","useEffect","useSelect","useDispatch","store","coreStore","useViewportMatch","archive","blockMeta","calendar","category","commentAuthorAvatar","edit","home","layout","list","media","notFound","page","pin","verse","search","tag","__","sprintf","noticesStore","privateApis","routerPrivateApis","focus","TEMPLATE_POST_TYPE","AddCustomTemplateModalContent","useExistingTemplates","useDefaultTemplateTypes","useTaxonomiesMenuItems","usePostTypeMenuItems","useAuthorMenuItem","usePostTypeArchiveMenuItems","AddCustomGenericTemplateModalContent","unlock","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","useHistory","DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","single","index","author","taxonomy","date","attachment","TemplateListItem","title","direction","className","description","icon","onClick","children","__next40pxDefaultSize","label","showTooltip","as","spacing","align","justify","style","width","alignment","weight","lineHeight","modalContentMap","templatesList","customTemplate","customGenericTemplate","NewTemplateModal","onClose","modalContent","setModalContent","entityForSuggestions","setEntityForSuggestions","isSubmitting","setIsSubmitting","missingTemplates","useMissingTemplates","history","saveEntityRecord","createErrorNotice","createSuccessNotice","containerRef","isMobile","homeUrl","select","getEntityRecord","TEMPLATE_SHORT_DESCRIPTIONS","Date","getFullYear","current","firstFocusable","focusable","find","createTemplate","template","isWPSuggestion","slug","newTemplate","toString","status","is_wp_suggestion","throwOnError","navigate","id","rendered","type","error","errorMessage","message","code","onModalClose","modalTitle","labels","singular_name","onRequestClose","overlayClassName","undefined","ref","columns","gap","map","onSelect","onBack","NewTemplate","showModal","setShowModal","postType","getPostType","variant","add_new_item","existingTemplates","defaultTemplateTypes","existingTemplateSlugs","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","enhancedMissingDefaultTemplateTypes","defaultTaxonomiesMenuItems","taxonomiesMenuItems","defaultPostTypesMenuItems","postTypesMenuItems","authorMenuItem","forEach","menuItem","matchIndex","findIndex","push","sort","template1","template2","indexOf"],"sources":["@wordpress/edit-site/src/components/add-new-template/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tModal,\n\t__experimentalGrid as Grid,\n\t__experimentalText as Text,\n\t__experimentalVStack as VStack,\n\tFlex,\n\tIcon,\n} from '@wordpress/components';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useState, memo, useRef, useEffect } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useViewportMatch } from '@wordpress/compose';\nimport {\n\tarchive,\n\tblockMeta,\n\tcalendar,\n\tcategory,\n\tcommentAuthorAvatar,\n\tedit,\n\thome,\n\tlayout,\n\tlist,\n\tmedia,\n\tnotFound,\n\tpage,\n\tpin,\n\tverse,\n\tsearch,\n\ttag,\n} from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { focus } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { TEMPLATE_POST_TYPE } from '../../utils/constants';\n\n/**\n * Internal dependencies\n */\nimport AddCustomTemplateModalContent from './add-custom-template-modal-content';\nimport {\n\tuseExistingTemplates,\n\tuseDefaultTemplateTypes,\n\tuseTaxonomiesMenuItems,\n\tusePostTypeMenuItems,\n\tuseAuthorMenuItem,\n\tusePostTypeArchiveMenuItems,\n} from './utils';\nimport AddCustomGenericTemplateModalContent from './add-custom-generic-template-modal-content';\nimport { unlock } from '../../lock-unlock';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nconst DEFAULT_TEMPLATE_SLUGS = [\n\t'front-page',\n\t'home',\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'search',\n\t'404',\n];\n\nconst TEMPLATE_ICONS = {\n\t'front-page': home,\n\thome: verse,\n\tsingle: pin,\n\tpage,\n\tarchive,\n\tsearch,\n\t404: notFound,\n\tindex: list,\n\tcategory,\n\tauthor: commentAuthorAvatar,\n\ttaxonomy: blockMeta,\n\tdate: calendar,\n\ttag,\n\tattachment: media,\n};\n\nfunction TemplateListItem( {\n\ttitle,\n\tdirection,\n\tclassName,\n\tdescription,\n\ticon,\n\tonClick,\n\tchildren,\n} ) {\n\treturn (\n\t\t<Button\n\t\t\t__next40pxDefaultSize\n\t\t\tclassName={ className }\n\t\t\tonClick={ onClick }\n\t\t\tlabel={ description }\n\t\t\tshowTooltip={ !! description }\n\t\t>\n\t\t\t<Flex\n\t\t\t\tas=\"span\"\n\t\t\t\tspacing={ 2 }\n\t\t\t\talign=\"center\"\n\t\t\t\tjustify=\"center\"\n\t\t\t\tstyle={ { width: '100%' } }\n\t\t\t\tdirection={ direction }\n\t\t\t>\n\t\t\t\t<div className=\"edit-site-add-new-template__template-icon\">\n\t\t\t\t\t<Icon icon={ icon } />\n\t\t\t\t</div>\n\t\t\t\t<VStack\n\t\t\t\t\tclassName=\"edit-site-add-new-template__template-name\"\n\t\t\t\t\talignment=\"center\"\n\t\t\t\t\tspacing={ 0 }\n\t\t\t\t>\n\t\t\t\t\t<Text\n\t\t\t\t\t\talign=\"center\"\n\t\t\t\t\t\tweight={ 500 }\n\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t>\n\t\t\t\t\t\t{ title }\n\t\t\t\t\t</Text>\n\t\t\t\t\t{ children }\n\t\t\t\t</VStack>\n\t\t\t</Flex>\n\t\t</Button>\n\t);\n}\n\nconst modalContentMap = {\n\ttemplatesList: 1,\n\tcustomTemplate: 2,\n\tcustomGenericTemplate: 3,\n};\n\nfunction NewTemplateModal( { onClose } ) {\n\tconst [ modalContent, setModalContent ] = useState(\n\t\tmodalContentMap.templatesList\n\t);\n\tconst [ entityForSuggestions, setEntityForSuggestions ] = useState( {} );\n\tconst [ isSubmitting, setIsSubmitting ] = useState( false );\n\tconst missingTemplates = useMissingTemplates( setEntityForSuggestions, () =>\n\t\tsetModalContent( modalContentMap.customTemplate )\n\t);\n\tconst history = useHistory();\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst containerRef = useRef( null );\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\n\tconst homeUrl = useSelect( ( select ) => {\n\t\t// Site index.\n\t\treturn select( coreStore ).getEntityRecord( 'root', '__unstableBase' )\n\t\t\t?.home;\n\t}, [] );\n\n\tconst TEMPLATE_SHORT_DESCRIPTIONS = {\n\t\t'front-page': homeUrl,\n\t\tdate: sprintf(\n\t\t\t// translators: %s: The homepage url.\n\t\t\t__( 'E.g. %s' ),\n\t\t\thomeUrl + '/' + new Date().getFullYear()\n\t\t),\n\t};\n\n\tuseEffect( () => {\n\t\t// Focus the first focusable element when component mounts or UI changes\n\t\t// We don't want to focus on the other modals because they have their own focus management.\n\t\tif (\n\t\t\tcontainerRef.current &&\n\t\t\tmodalContent === modalContentMap.templatesList\n\t\t) {\n\t\t\tconst [ firstFocusable ] = focus.focusable.find(\n\t\t\t\tcontainerRef.current\n\t\t\t);\n\t\t\tfirstFocusable?.focus();\n\t\t}\n\t}, [ modalContent ] );\n\n\tasync function createTemplate( template, isWPSuggestion = true ) {\n\t\tif ( isSubmitting ) {\n\t\t\treturn;\n\t\t}\n\t\tsetIsSubmitting( true );\n\t\ttry {\n\t\t\tconst { title, description, slug } = template;\n\t\t\tconst newTemplate = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tTEMPLATE_POST_TYPE,\n\t\t\t\t{\n\t\t\t\t\tdescription,\n\t\t\t\t\t// Slugs need to be strings, so this is for template `404`\n\t\t\t\t\tslug: slug.toString(),\n\t\t\t\t\tstatus: 'publish',\n\t\t\t\t\ttitle,\n\t\t\t\t\t// This adds a post meta field in template that is part of `is_custom` value calculation.\n\t\t\t\t\tis_wp_suggestion: isWPSuggestion,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\t// Navigate to the created template editor.\n\t\t\thistory.navigate(\n\t\t\t\t`/${ TEMPLATE_POST_TYPE }/${ newTemplate.id }?canvas=edit`\n\t\t\t);\n\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: Title of the created post or template, e.g: \"Hello world\".\n\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\tdecodeEntities( newTemplate.title?.rendered || title )\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while creating the template.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t} finally {\n\t\t\tsetIsSubmitting( false );\n\t\t}\n\t}\n\tconst onModalClose = () => {\n\t\tonClose();\n\t\tsetModalContent( modalContentMap.templatesList );\n\t};\n\n\tlet modalTitle = __( 'Add template' );\n\tif ( modalContent === modalContentMap.customTemplate ) {\n\t\tmodalTitle = sprintf(\n\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t__( 'Add template: %s' ),\n\t\t\tentityForSuggestions.labels.singular_name\n\t\t);\n\t} else if ( modalContent === modalContentMap.customGenericTemplate ) {\n\t\tmodalTitle = __( 'Create custom template' );\n\t}\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ modalTitle }\n\t\t\tclassName={ clsx( 'edit-site-add-new-template__modal', {\n\t\t\t\t'edit-site-add-new-template__modal_template_list':\n\t\t\t\t\tmodalContent === modalContentMap.templatesList,\n\t\t\t\t'edit-site-custom-template-modal':\n\t\t\t\t\tmodalContent === modalContentMap.customTemplate,\n\t\t\t} ) }\n\t\t\tonRequestClose={ onModalClose }\n\t\t\toverlayClassName={\n\t\t\t\tmodalContent === modalContentMap.customGenericTemplate\n\t\t\t\t\t? 'edit-site-custom-generic-template__modal'\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\tref={ containerRef }\n\t\t>\n\t\t\t{ modalContent === modalContentMap.templatesList && (\n\t\t\t\t<Grid\n\t\t\t\t\tcolumns={ isMobile ? 2 : 3 }\n\t\t\t\t\tgap={ 4 }\n\t\t\t\t\talign=\"flex-start\"\n\t\t\t\t\tjustify=\"center\"\n\t\t\t\t\tclassName=\"edit-site-add-new-template__template-list__contents\"\n\t\t\t\t>\n\t\t\t\t\t<Flex className=\"edit-site-add-new-template__template-list__prompt\">\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Select what the new template should apply to:'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Flex>\n\t\t\t\t\t{ missingTemplates.map( ( template ) => {\n\t\t\t\t\t\tconst { title, slug, onClick } = template;\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<TemplateListItem\n\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\ttitle={ title }\n\t\t\t\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\t\t\t\tclassName=\"edit-site-add-new-template__template-button\"\n\t\t\t\t\t\t\t\tdescription={\n\t\t\t\t\t\t\t\t\tTEMPLATE_SHORT_DESCRIPTIONS[ slug ]\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\ticon={ TEMPLATE_ICONS[ slug ] || layout }\n\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\tonClick\n\t\t\t\t\t\t\t\t\t\t? onClick( template )\n\t\t\t\t\t\t\t\t\t\t: createTemplate( template )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t);\n\t\t\t\t\t} ) }\n\t\t\t\t\t<TemplateListItem\n\t\t\t\t\t\ttitle={ __( 'Custom template' ) }\n\t\t\t\t\t\tdirection=\"row\"\n\t\t\t\t\t\tclassName=\"edit-site-add-new-template__custom-template-button\"\n\t\t\t\t\t\ticon={ edit }\n\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\tsetModalContent(\n\t\t\t\t\t\t\t\tmodalContentMap.customGenericTemplate\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Text\n\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'A custom template can be manually applied to any post or page.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</Text>\n\t\t\t\t\t</TemplateListItem>\n\t\t\t\t</Grid>\n\t\t\t) }\n\t\t\t{ modalContent === modalContentMap.customTemplate && (\n\t\t\t\t<AddCustomTemplateModalContent\n\t\t\t\t\tonSelect={ createTemplate }\n\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\tonBack={ () =>\n\t\t\t\t\t\tsetModalContent( modalContentMap.templatesList )\n\t\t\t\t\t}\n\t\t\t\t\tcontainerRef={ containerRef }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ modalContent === modalContentMap.customGenericTemplate && (\n\t\t\t\t<AddCustomGenericTemplateModalContent\n\t\t\t\t\tcreateTemplate={ createTemplate }\n\t\t\t\t\tonBack={ () =>\n\t\t\t\t\t\tsetModalContent( modalContentMap.templatesList )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t) }\n\t\t</Modal>\n\t);\n}\n\nfunction NewTemplate() {\n\tconst [ showModal, setShowModal ] = useState( false );\n\n\tconst { postType } = useSelect( ( select ) => {\n\t\tconst { getPostType } = select( coreStore );\n\n\t\treturn {\n\t\t\tpostType: getPostType( TEMPLATE_POST_TYPE ),\n\t\t};\n\t}, [] );\n\n\tif ( ! postType ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tvariant=\"primary\"\n\t\t\t\tonClick={ () => setShowModal( true ) }\n\t\t\t\tlabel={ postType.labels.add_new_item }\n\t\t\t\t__next40pxDefaultSize\n\t\t\t>\n\t\t\t\t{ postType.labels.add_new_item }\n\t\t\t</Button>\n\t\t\t{ showModal && (\n\t\t\t\t<NewTemplateModal onClose={ () => setShowModal( false ) } />\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction useMissingTemplates( setEntityForSuggestions, onClick ) {\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\tonClick?.();\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\nexport default memo( NewTemplate );\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,IAAI,MAAM,MAAM;;AAEvB;AACA;AACA;AACA,SACCC,MAAM,EACNC,KAAK,EACLC,kBAAkB,IAAIC,IAAI,EAC1BC,kBAAkB,IAAIC,IAAI,EAC1BC,oBAAoB,IAAIC,MAAM,EAC9BC,IAAI,EACJC,IAAI,QACE,uBAAuB;AAC9B,SAASC,cAAc,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A;IACA,IAAKkD,UAAU,GAAG,CAAC,CAAC,EAAG;MACtBR,mCAAmC,CAAEQ,UAAU,CAAE,GAAGD,QAAQ;IAC7D,CAAC,MAAM;MACNP,mCAAmC,CAACU,IAAI,CAAEH,QAAS,CAAC;IACrD;EACD,CAAE,CAAC;EACH;EACAP,mCAAmC,EAAEW,IAAI,CAAE,CAAEC,SAAS,EAAEC,SAAS,KAAM;IACtE,OACCpH,sBAAsB,CAACqH,OAAO,CAAEF,SAAS,CAACtD,IAAK,CAAC,GAChD7D,sBAAsB,CAACqH,OAAO,CAAED,SAAS,CAACvD,IAAK,CAAC;EAElD,CAAE,CAAC;EACH,MAAMrB,gBAAgB,GAAG,CACxB,GAAG+D,mCAAmC,EACtC,GAAGjH,2BAA2B,CAAC,CAAC,EAChC,GAAGqH,kBAAkB,EACrB,GAAGF,mBAAmB,CACtB;EACD,OAAOjE,gBAAgB;AACxB;AAEA,eAAevF,IAAI,CAAEuI,WAAY,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["clsx","Button","Modal","__experimentalGrid","Grid","__experimentalText","Text","__experimentalVStack","VStack","Flex","Icon","decodeEntities","useState","memo","useRef","useEffect","useSelect","useDispatch","store","coreStore","useViewportMatch","archive","blockMeta","calendar","category","commentAuthorAvatar","edit","home","layout","list","media","notFound","page","pin","verse","search","tag","__","sprintf","noticesStore","privateApis","routerPrivateApis","focus","TEMPLATE_POST_TYPE","AddCustomTemplateModalContent","useDefaultTemplateTypes","useTaxonomiesMenuItems","usePostTypeMenuItems","useAuthorMenuItem","usePostTypeArchiveMenuItems","AddCustomGenericTemplateModalContent","unlock","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","useHistory","DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","single","index","author","taxonomy","date","attachment","TemplateListItem","title","direction","className","description","icon","onClick","children","__next40pxDefaultSize","label","showTooltip","as","spacing","align","justify","style","width","alignment","weight","lineHeight","modalContentMap","templatesList","customTemplate","customGenericTemplate","NewTemplateModal","onClose","modalContent","setModalContent","entityForSuggestions","setEntityForSuggestions","isSubmitting","setIsSubmitting","missingTemplates","useMissingTemplates","history","saveEntityRecord","createErrorNotice","createSuccessNotice","containerRef","isMobile","homeUrl","select","getEntityRecord","TEMPLATE_SHORT_DESCRIPTIONS","Date","getFullYear","current","firstFocusable","focusable","find","createTemplate","template","isWPSuggestion","slug","newTemplate","toString","status","is_wp_suggestion","throwOnError","navigate","id","rendered","type","error","errorMessage","message","code","onModalClose","modalTitle","labels","singular_name","onRequestClose","overlayClassName","undefined","ref","columns","gap","map","onSelect","onBack","NewTemplate","showModal","setShowModal","postType","getPostType","variant","add_new_item","defaultTemplateTypes","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","enhancedMissingDefaultTemplateTypes","defaultTaxonomiesMenuItems","taxonomiesMenuItems","defaultPostTypesMenuItems","postTypesMenuItems","authorMenuItem","forEach","menuItem","matchIndex","findIndex","push","sort","template1","template2","indexOf"],"sources":["@wordpress/edit-site/src/components/add-new-template/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tModal,\n\t__experimentalGrid as Grid,\n\t__experimentalText as Text,\n\t__experimentalVStack as VStack,\n\tFlex,\n\tIcon,\n} from '@wordpress/components';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useState, memo, useRef, useEffect } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useViewportMatch } from '@wordpress/compose';\nimport {\n\tarchive,\n\tblockMeta,\n\tcalendar,\n\tcategory,\n\tcommentAuthorAvatar,\n\tedit,\n\thome,\n\tlayout,\n\tlist,\n\tmedia,\n\tnotFound,\n\tpage,\n\tpin,\n\tverse,\n\tsearch,\n\ttag,\n} from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { focus } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { TEMPLATE_POST_TYPE } from '../../utils/constants';\n\n/**\n * Internal dependencies\n */\nimport AddCustomTemplateModalContent from './add-custom-template-modal-content';\nimport {\n\tuseDefaultTemplateTypes,\n\tuseTaxonomiesMenuItems,\n\tusePostTypeMenuItems,\n\tuseAuthorMenuItem,\n\tusePostTypeArchiveMenuItems,\n} from './utils';\nimport AddCustomGenericTemplateModalContent from './add-custom-generic-template-modal-content';\nimport { unlock } from '../../lock-unlock';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nconst DEFAULT_TEMPLATE_SLUGS = [\n\t'front-page',\n\t'home',\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'search',\n\t'404',\n];\n\nconst TEMPLATE_ICONS = {\n\t'front-page': home,\n\thome: verse,\n\tsingle: pin,\n\tpage,\n\tarchive,\n\tsearch,\n\t404: notFound,\n\tindex: list,\n\tcategory,\n\tauthor: commentAuthorAvatar,\n\ttaxonomy: blockMeta,\n\tdate: calendar,\n\ttag,\n\tattachment: media,\n};\n\nfunction TemplateListItem( {\n\ttitle,\n\tdirection,\n\tclassName,\n\tdescription,\n\ticon,\n\tonClick,\n\tchildren,\n} ) {\n\treturn (\n\t\t<Button\n\t\t\t__next40pxDefaultSize\n\t\t\tclassName={ className }\n\t\t\tonClick={ onClick }\n\t\t\tlabel={ description }\n\t\t\tshowTooltip={ !! description }\n\t\t>\n\t\t\t<Flex\n\t\t\t\tas=\"span\"\n\t\t\t\tspacing={ 2 }\n\t\t\t\talign=\"center\"\n\t\t\t\tjustify=\"center\"\n\t\t\t\tstyle={ { width: '100%' } }\n\t\t\t\tdirection={ direction }\n\t\t\t>\n\t\t\t\t<div className=\"edit-site-add-new-template__template-icon\">\n\t\t\t\t\t<Icon icon={ icon } />\n\t\t\t\t</div>\n\t\t\t\t<VStack\n\t\t\t\t\tclassName=\"edit-site-add-new-template__template-name\"\n\t\t\t\t\talignment=\"center\"\n\t\t\t\t\tspacing={ 0 }\n\t\t\t\t>\n\t\t\t\t\t<Text\n\t\t\t\t\t\talign=\"center\"\n\t\t\t\t\t\tweight={ 500 }\n\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t>\n\t\t\t\t\t\t{ title }\n\t\t\t\t\t</Text>\n\t\t\t\t\t{ children }\n\t\t\t\t</VStack>\n\t\t\t</Flex>\n\t\t</Button>\n\t);\n}\n\nconst modalContentMap = {\n\ttemplatesList: 1,\n\tcustomTemplate: 2,\n\tcustomGenericTemplate: 3,\n};\n\nfunction NewTemplateModal( { onClose } ) {\n\tconst [ modalContent, setModalContent ] = useState(\n\t\tmodalContentMap.templatesList\n\t);\n\tconst [ entityForSuggestions, setEntityForSuggestions ] = useState( {} );\n\tconst [ isSubmitting, setIsSubmitting ] = useState( false );\n\tconst missingTemplates = useMissingTemplates( setEntityForSuggestions, () =>\n\t\tsetModalContent( modalContentMap.customTemplate )\n\t);\n\tconst history = useHistory();\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst containerRef = useRef( null );\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\n\tconst homeUrl = useSelect( ( select ) => {\n\t\t// Site index.\n\t\treturn select( coreStore ).getEntityRecord( 'root', '__unstableBase' )\n\t\t\t?.home;\n\t}, [] );\n\n\tconst TEMPLATE_SHORT_DESCRIPTIONS = {\n\t\t'front-page': homeUrl,\n\t\tdate: sprintf(\n\t\t\t// translators: %s: The homepage url.\n\t\t\t__( 'E.g. %s' ),\n\t\t\thomeUrl + '/' + new Date().getFullYear()\n\t\t),\n\t};\n\n\tuseEffect( () => {\n\t\t// Focus the first focusable element when component mounts or UI changes\n\t\t// We don't want to focus on the other modals because they have their own focus management.\n\t\tif (\n\t\t\tcontainerRef.current &&\n\t\t\tmodalContent === modalContentMap.templatesList\n\t\t) {\n\t\t\tconst [ firstFocusable ] = focus.focusable.find(\n\t\t\t\tcontainerRef.current\n\t\t\t);\n\t\t\tfirstFocusable?.focus();\n\t\t}\n\t}, [ modalContent ] );\n\n\tasync function createTemplate( template, isWPSuggestion = true ) {\n\t\tif ( isSubmitting ) {\n\t\t\treturn;\n\t\t}\n\t\tsetIsSubmitting( true );\n\t\ttry {\n\t\t\tconst { title, description, slug } = template;\n\t\t\tconst newTemplate = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tTEMPLATE_POST_TYPE,\n\t\t\t\t{\n\t\t\t\t\tdescription,\n\t\t\t\t\t// Slugs need to be strings, so this is for template `404`\n\t\t\t\t\tslug: slug.toString(),\n\t\t\t\t\tstatus: 'publish',\n\t\t\t\t\ttitle,\n\t\t\t\t\t// This adds a post meta field in template that is part of `is_custom` value calculation.\n\t\t\t\t\tis_wp_suggestion: isWPSuggestion,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\t// Navigate to the created template editor.\n\t\t\thistory.navigate(\n\t\t\t\t`/${ TEMPLATE_POST_TYPE }/${ newTemplate.id }?canvas=edit`\n\t\t\t);\n\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: Title of the created post or template, e.g: \"Hello world\".\n\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\tdecodeEntities( newTemplate.title?.rendered || title )\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while creating the template.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t} finally {\n\t\t\tsetIsSubmitting( false );\n\t\t}\n\t}\n\tconst onModalClose = () => {\n\t\tonClose();\n\t\tsetModalContent( modalContentMap.templatesList );\n\t};\n\n\tlet modalTitle = __( 'Add template' );\n\tif ( modalContent === modalContentMap.customTemplate ) {\n\t\tmodalTitle = sprintf(\n\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t__( 'Add template: %s' ),\n\t\t\tentityForSuggestions.labels.singular_name\n\t\t);\n\t} else if ( modalContent === modalContentMap.customGenericTemplate ) {\n\t\tmodalTitle = __( 'Create custom template' );\n\t}\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ modalTitle }\n\t\t\tclassName={ clsx( 'edit-site-add-new-template__modal', {\n\t\t\t\t'edit-site-add-new-template__modal_template_list':\n\t\t\t\t\tmodalContent === modalContentMap.templatesList,\n\t\t\t\t'edit-site-custom-template-modal':\n\t\t\t\t\tmodalContent === modalContentMap.customTemplate,\n\t\t\t} ) }\n\t\t\tonRequestClose={ onModalClose }\n\t\t\toverlayClassName={\n\t\t\t\tmodalContent === modalContentMap.customGenericTemplate\n\t\t\t\t\t? 'edit-site-custom-generic-template__modal'\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\tref={ containerRef }\n\t\t>\n\t\t\t{ modalContent === modalContentMap.templatesList && (\n\t\t\t\t<Grid\n\t\t\t\t\tcolumns={ isMobile ? 2 : 3 }\n\t\t\t\t\tgap={ 4 }\n\t\t\t\t\talign=\"flex-start\"\n\t\t\t\t\tjustify=\"center\"\n\t\t\t\t\tclassName=\"edit-site-add-new-template__template-list__contents\"\n\t\t\t\t>\n\t\t\t\t\t<Flex className=\"edit-site-add-new-template__template-list__prompt\">\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Select what the new template should apply to:'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Flex>\n\t\t\t\t\t{ missingTemplates.map( ( template ) => {\n\t\t\t\t\t\tconst { title, slug, onClick } = template;\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<TemplateListItem\n\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\ttitle={ title }\n\t\t\t\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\t\t\t\tclassName=\"edit-site-add-new-template__template-button\"\n\t\t\t\t\t\t\t\tdescription={\n\t\t\t\t\t\t\t\t\tTEMPLATE_SHORT_DESCRIPTIONS[ slug ]\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\ticon={ TEMPLATE_ICONS[ slug ] || layout }\n\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\tonClick\n\t\t\t\t\t\t\t\t\t\t? onClick( template )\n\t\t\t\t\t\t\t\t\t\t: createTemplate( template )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t);\n\t\t\t\t\t} ) }\n\t\t\t\t\t<TemplateListItem\n\t\t\t\t\t\ttitle={ __( 'Custom template' ) }\n\t\t\t\t\t\tdirection=\"row\"\n\t\t\t\t\t\tclassName=\"edit-site-add-new-template__custom-template-button\"\n\t\t\t\t\t\ticon={ edit }\n\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\tsetModalContent(\n\t\t\t\t\t\t\t\tmodalContentMap.customGenericTemplate\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Text\n\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'A custom template can be manually applied to any post or page.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</Text>\n\t\t\t\t\t</TemplateListItem>\n\t\t\t\t</Grid>\n\t\t\t) }\n\t\t\t{ modalContent === modalContentMap.customTemplate && (\n\t\t\t\t<AddCustomTemplateModalContent\n\t\t\t\t\tonSelect={ createTemplate }\n\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\tonBack={ () =>\n\t\t\t\t\t\tsetModalContent( modalContentMap.templatesList )\n\t\t\t\t\t}\n\t\t\t\t\tcontainerRef={ containerRef }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ modalContent === modalContentMap.customGenericTemplate && (\n\t\t\t\t<AddCustomGenericTemplateModalContent\n\t\t\t\t\tcreateTemplate={ createTemplate }\n\t\t\t\t\tonBack={ () =>\n\t\t\t\t\t\tsetModalContent( modalContentMap.templatesList )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t) }\n\t\t</Modal>\n\t);\n}\n\nfunction NewTemplate() {\n\tconst [ showModal, setShowModal ] = useState( false );\n\n\tconst { postType } = useSelect( ( select ) => {\n\t\tconst { getPostType } = select( coreStore );\n\n\t\treturn {\n\t\t\tpostType: getPostType( TEMPLATE_POST_TYPE ),\n\t\t};\n\t}, [] );\n\n\tif ( ! postType ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tvariant=\"primary\"\n\t\t\t\tonClick={ () => setShowModal( true ) }\n\t\t\t\tlabel={ postType.labels.add_new_item }\n\t\t\t\t__next40pxDefaultSize\n\t\t\t>\n\t\t\t\t{ postType.labels.add_new_item }\n\t\t\t</Button>\n\t\t\t{ showModal && (\n\t\t\t\t<NewTemplateModal onClose={ () => setShowModal( false ) } />\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction useMissingTemplates( setEntityForSuggestions, onClick ) {\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst missingDefaultTemplates = ( defaultTemplateTypes || [] ).filter(\n\t\t( template ) => DEFAULT_TEMPLATE_SLUGS.includes( template.slug )\n\t);\n\tconst onClickMenuItem = ( _entityForSuggestions ) => {\n\t\tonClick?.();\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\nexport default memo( NewTemplate );\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,IAAI,MAAM,MAAM;;AAEvB;AACA;AACA;AACA,SACCC,MAAM,EACNC,KAAK,EACLC,kBAAkB,IAAIC,IAAI,EAC1BC,kBAAkB,IAAIC,IAAI,EA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;EACD,CAAE,CAAC;EACH;EACAP,mCAAmC,EAAEW,IAAI,CAAE,CAAEC,SAAS,EAAEC,SAAS,KAAM;IACtE,OACClH,sBAAsB,CAACmH,OAAO,CAAEF,SAAS,CAACpD,IAAK,CAAC,GAChD7D,sBAAsB,CAACmH,OAAO,CAAED,SAAS,CAACrD,IAAK,CAAC;EAElD,CAAE,CAAC;EACH,MAAMrB,gBAAgB,GAAG,CACxB,GAAG6D,mCAAmC,EACtC,GAAG/G,2BAA2B,CAAC,CAAC,EAChC,GAAGmH,kBAAkB,EACrB,GAAGF,mBAAmB,CACtB;EACD,OAAO/D,gBAAgB;AACxB;AAEA,eAAetF,IAAI,CAAEsI,WAAY,CAAC","ignoreList":[]}
@@ -7,6 +7,7 @@ import { decodeEntities } from '@wordpress/html-entities';
7
7
  import { useMemo, useCallback } from '@wordpress/element';
8
8
  import { __, _x, sprintf } from '@wordpress/i18n';
9
9
  import { blockMeta, post, archive } from '@wordpress/icons';
10
+ import { safeDecodeURI } from '@wordpress/url';
10
11
 
11
12
  /**
12
13
  * Internal dependencies
@@ -28,6 +29,20 @@ const getValueFromObjectPath = (object, path) => {
28
29
  return value;
29
30
  };
30
31
 
32
+ /**
33
+ * Helper that adds a prefix to a post slug. The slug needs to be URL-decoded first,
34
+ * so that we have raw Unicode characters there. The server will truncate the slug to
35
+ * 200 characters, respecing Unicode char boundary. On the other hand, the server
36
+ * doesn't detect urlencoded octet boundary and can possibly construct slugs that
37
+ * are not valid urlencoded strings.
38
+ * @param {string} prefix The prefix to add to the slug.
39
+ * @param {string} slug The slug to add the prefix to.
40
+ * @return {string} The slug with the prefix.
41
+ */
42
+ function prefixSlug(prefix, slug) {
43
+ return `${prefix}-${safeDecodeURI(slug)}`;
44
+ }
45
+
31
46
  /**
32
47
  * Helper util to map records to add a `name` prop from a
33
48
  * provided path, in order to handle all entities in the same
@@ -134,7 +149,6 @@ export function usePostTypeArchiveMenuItems() {
134
149
  }
135
150
  export const usePostTypeMenuItems = onClickMenuItem => {
136
151
  const publicPostTypes = usePublicPostTypes();
137
- const existingTemplates = useExistingTemplates();
138
152
  const defaultTemplateTypes = useDefaultTemplateTypes();
139
153
  // We need to keep track of naming conflicts. If a conflict
140
154
  // occurs, we need to add slug.
@@ -165,9 +179,6 @@ export const usePostTypeMenuItems = onClickMenuItem => {
165
179
  return accumulator;
166
180
  }, {}), [publicPostTypes]);
167
181
  const postTypesInfo = useEntitiesInfo('postType', templatePrefixes);
168
- const existingTemplateSlugs = (existingTemplates || []).map(({
169
- slug
170
- }) => slug);
171
182
  const menuItems = (publicPostTypes || []).reduce((accumulator, postType) => {
172
183
  const {
173
184
  slug,
@@ -181,7 +192,6 @@ export const usePostTypeMenuItems = onClickMenuItem => {
181
192
  const defaultTemplateType = defaultTemplateTypes?.find(({
182
193
  slug: _slug
183
194
  }) => _slug === generalTemplateSlug);
184
- const hasGeneralTemplate = existingTemplateSlugs?.includes(generalTemplateSlug);
185
195
  const _needsUniqueIdentifier = needsUniqueIdentifier(postType);
186
196
  let menuItemTitle = labels.template_name || sprintf(
187
197
  // translators: %s: Name of the post type e.g: "Post".
@@ -227,7 +237,7 @@ export const usePostTypeMenuItems = onClickMenuItem => {
227
237
  };
228
238
  },
229
239
  getSpecificTemplate: suggestion => {
230
- const templateSlug = `${templatePrefixes[slug]}-${suggestion.slug}`;
240
+ const templateSlug = prefixSlug(templatePrefixes[slug], suggestion.slug);
231
241
  return {
232
242
  title: templateSlug,
233
243
  slug: templateSlug,
@@ -236,14 +246,12 @@ export const usePostTypeMenuItems = onClickMenuItem => {
236
246
  }
237
247
  },
238
248
  labels,
239
- hasGeneralTemplate,
240
249
  template
241
250
  });
242
251
  };
243
252
  }
244
- // We don't need to add the menu item if there are no
245
- // entities and the general template exists.
246
- if (!hasGeneralTemplate || hasEntities) {
253
+ // We don't need to add the menu item if there are no entities.
254
+ if (hasEntities) {
247
255
  accumulator.push(menuItem);
248
256
  }
249
257
  return accumulator;
@@ -356,7 +364,7 @@ export const useTaxonomiesMenuItems = onClickMenuItem => {
356
364
  };
357
365
  },
358
366
  getSpecificTemplate: suggestion => {
359
- const templateSlug = `${templatePrefixes[slug]}-${suggestion.slug}`;
367
+ const templateSlug = prefixSlug(templatePrefixes[slug], suggestion.slug);
360
368
  return {
361
369
  title: templateSlug,
362
370
  slug: templateSlug,
@@ -441,9 +449,11 @@ export function useAuthorMenuItem(onClickMenuItem) {
441
449
  };
442
450
  },
443
451
  getSpecificTemplate: suggestion => {
444
- const templateSlug = `author-${suggestion.slug}`;
452
+ const templateSlug = prefixSlug('author', suggestion.slug);
445
453
  return {
446
- title: templateSlug,
454
+ title: sprintf(
455
+ // translators: %s: Name of the author e.g: "Admin".
456
+ __('Author: %s'), suggestion.name),
447
457
  slug: templateSlug,
448
458
  templatePrefix: 'author'
449
459
  };
@@ -465,68 +475,6 @@ export function useAuthorMenuItem(onClickMenuItem) {
465
475
  }
466
476
  }
467
477
 
468
- /**
469
- * Helper hook that filters all the existing templates by the given
470
- * object with the entity's slug as key and the template prefix as value.
471
- *
472
- * Example:
473
- * `existingTemplates` is: [ { slug: 'tag-apple' }, { slug: 'page-about' }, { slug: 'tag' } ]
474
- * `templatePrefixes` is: { post_tag: 'tag' }
475
- * It will return: { post_tag: ['apple'] }
476
- *
477
- * Note: We append the `-` to the given template prefix in this function for our checks.
478
- *
479
- * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.
480
- * @return {Record<string,string[]>} An object with the entity's slug as key and an array with the existing template slugs as value.
481
- */
482
- const useExistingTemplateSlugs = templatePrefixes => {
483
- const existingTemplates = useExistingTemplates();
484
- const existingSlugs = useMemo(() => {
485
- return Object.entries(templatePrefixes || {}).reduce((accumulator, [slug, prefix]) => {
486
- const slugsWithTemplates = (existingTemplates || []).reduce((_accumulator, existingTemplate) => {
487
- const _prefix = `${prefix}-`;
488
- if (existingTemplate.slug.startsWith(_prefix)) {
489
- _accumulator.push(existingTemplate.slug.substring(_prefix.length));
490
- }
491
- return _accumulator;
492
- }, []);
493
- if (slugsWithTemplates.length) {
494
- accumulator[slug] = slugsWithTemplates;
495
- }
496
- return accumulator;
497
- }, {});
498
- }, [templatePrefixes, existingTemplates]);
499
- return existingSlugs;
500
- };
501
-
502
- /**
503
- * Helper hook that finds the existing records with an associated template,
504
- * as they need to be excluded from the template suggestions.
505
- *
506
- * @param {string} entityName The entity's name.
507
- * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.
508
- * @param {Record<string,Object>} additionalQueryParameters An object with the entity's slug as key and additional query parameters as value.
509
- * @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the existing records as value.
510
- */
511
- const useTemplatesToExclude = (entityName, templatePrefixes, additionalQueryParameters = {}) => {
512
- const slugsToExcludePerEntity = useExistingTemplateSlugs(templatePrefixes);
513
- const recordsToExcludePerEntity = useSelect(select => {
514
- return Object.entries(slugsToExcludePerEntity || {}).reduce((accumulator, [slug, slugsWithTemplates]) => {
515
- const entitiesWithTemplates = select(coreStore).getEntityRecords(entityName, slug, {
516
- _fields: 'id',
517
- context: 'view',
518
- slug: slugsWithTemplates,
519
- ...additionalQueryParameters[slug]
520
- });
521
- if (entitiesWithTemplates?.length) {
522
- accumulator[slug] = entitiesWithTemplates;
523
- }
524
- return accumulator;
525
- }, {});
526
- }, [slugsToExcludePerEntity]);
527
- return recordsToExcludePerEntity;
528
- };
529
-
530
478
  /**
531
479
  * Helper hook that returns information about an entity having
532
480
  * records that we can create a specific template for.
@@ -543,34 +491,25 @@ const useTemplatesToExclude = (entityName, templatePrefixes, additionalQueryPara
543
491
  * @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the EntitiesInfo as value.
544
492
  */
545
493
  const useEntitiesInfo = (entityName, templatePrefixes, additionalQueryParameters = EMPTY_OBJECT) => {
546
- const recordsToExcludePerEntity = useTemplatesToExclude(entityName, templatePrefixes, additionalQueryParameters);
547
494
  const entitiesHasRecords = useSelect(select => {
548
495
  return Object.keys(templatePrefixes || {}).reduce((accumulator, slug) => {
549
- const existingEntitiesIds = recordsToExcludePerEntity?.[slug]?.map(({
550
- id
551
- }) => id) || [];
552
496
  accumulator[slug] = !!select(coreStore).getEntityRecords(entityName, slug, {
553
497
  per_page: 1,
554
498
  _fields: 'id',
555
499
  context: 'view',
556
- exclude: existingEntitiesIds,
557
500
  ...additionalQueryParameters[slug]
558
501
  })?.length;
559
502
  return accumulator;
560
503
  }, {});
561
- }, [templatePrefixes, recordsToExcludePerEntity, entityName, additionalQueryParameters]);
504
+ }, [templatePrefixes, entityName, additionalQueryParameters]);
562
505
  const entitiesInfo = useMemo(() => {
563
506
  return Object.keys(templatePrefixes || {}).reduce((accumulator, slug) => {
564
- const existingEntitiesIds = recordsToExcludePerEntity?.[slug]?.map(({
565
- id
566
- }) => id) || [];
567
507
  accumulator[slug] = {
568
- hasEntities: entitiesHasRecords[slug],
569
- existingEntitiesIds
508
+ hasEntities: entitiesHasRecords[slug]
570
509
  };
571
510
  return accumulator;
572
511
  }, {});
573
- }, [templatePrefixes, recordsToExcludePerEntity, entitiesHasRecords]);
512
+ }, [templatePrefixes, entitiesHasRecords]);
574
513
  return entitiesInfo;
575
514
  };
576
515
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useSelect","store","coreStore","decodeEntities","useMemo","useCallback","__","_x","sprintf","blockMeta","post","archive","TEMPLATE_POST_TYPE","EMPTY_OBJECT","getValueFromObjectPath","object","path","value","split","forEach","fieldName","mapToIHasNameAndId","entities","map","entity","name","useExistingTemplates","select","getEntityRecords","per_page","useDefaultTemplateTypes","getCurrentTheme","default_template_types","usePublicPostTypes","postTypes","getPostTypes","excludedPostTypes","filter","viewable","slug","includes","sort","a","b","localeCompare","usePublicTaxonomies","taxonomies","getTaxonomies","visibility","publicly_queryable","usePostTypeArchiveMenuItems","publicPostTypes","postTypesWithArchives","postType","has_archive","existingTemplates","postTypeLabels","reduce","accumulator","labels","singularName","singular_name","toLowerCase","needsUniqueIdentifier","some","existingTemplate","title","description","icon","startsWith","slice","templatePrefix","usePostTypeMenuItems","onClickMenuItem","defaultTemplateTypes","templateLabels","templateName","template_name","templatePrefixes","suffix","postTypesInfo","useEntitiesInfo","existingTemplateSlugs","menuItems","generalTemplateSlug","defaultTemplateType","find","_slug","hasGeneralTemplate","_needsUniqueIdentifier","menuItemTitle","menuItem","hasEntities","onClick","template","type","config","recordNamePath","queryArgs","search","_fields","orderBy","exclude","existingEntitiesIds","getSpecificTemplate","suggestion","templateSlug","push","postTypesMenuItems","key","defaultPostTypesMenuItems","useTaxonomiesMenuItems","publicTaxonomies","taxonomyLabels","taxonomiesInfo","taxonomy","taxonomiesMenuItems","defaultTaxonomiesMenuItems","USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX","user","USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS","who","useAuthorMenuItem","authorInfo","authorMenuItem","search_items","not_found","all_items","useExistingTemplateSlugs","existingSlugs","Object","entries","prefix","slugsWithTemplates","_accumulator","_prefix","substring","length","useTemplatesToExclude","entityName","additionalQueryParameters","slugsToExcludePerEntity","recordsToExcludePerEntity","entitiesWithTemplates","context","entitiesHasRecords","keys","id","entitiesInfo"],"sources":["@wordpress/edit-site/src/components/add-new-template/utils.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useMemo, useCallback } from '@wordpress/element';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { blockMeta, post, archive } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { TEMPLATE_POST_TYPE } from '../../utils/constants';\n\nconst EMPTY_OBJECT = {};\n\n/**\n * @typedef IHasNameAndId\n * @property {string|number} id The entity's id.\n * @property {string} name The entity's name.\n */\n\nconst getValueFromObjectPath = ( object, path ) => {\n\tlet value = object;\n\tpath.split( '.' ).forEach( ( fieldName ) => {\n\t\tvalue = value?.[ fieldName ];\n\t} );\n\treturn value;\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 entities 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( getValueFromObjectPath( 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(\n\t\t\t\t'postType',\n\t\t\t\tTEMPLATE_POST_TYPE,\n\t\t\t\t{\n\t\t\t\t\tper_page: -1,\n\t\t\t\t}\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( coreStore ).getCurrentTheme()?.default_template_types || [],\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\n\t\t\t?.filter(\n\t\t\t\t( { viewable, slug } ) =>\n\t\t\t\t\tviewable && ! excludedPostTypes.includes( slug )\n\t\t\t)\n\t\t\t.sort( ( a, b ) => {\n\t\t\t\t// Sort post types alphabetically by name,\n\t\t\t\t// but exclude the built-in 'post' type from sorting.\n\t\t\t\tif ( a.slug === 'post' || b.slug === 'post' ) {\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\n\t\t\t\treturn a.name.localeCompare( b.name );\n\t\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 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\t// We need to keep track of naming conflicts. If a conflict\n\t// occurs, we need to add slug.\n\tconst postTypeLabels = useMemo(\n\t\t() =>\n\t\t\tpublicPostTypes?.reduce( ( accumulator, { labels } ) => {\n\t\t\t\tconst singularName = labels.singular_name.toLowerCase();\n\t\t\t\taccumulator[ singularName ] =\n\t\t\t\t\t( accumulator[ singularName ] || 0 ) + 1;\n\t\t\t\treturn accumulator;\n\t\t\t}, {} ),\n\t\t[ publicPostTypes ]\n\t);\n\tconst needsUniqueIdentifier = 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\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 latest 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:\n\t\t\t\t\t\t\ttypeof postType.icon === 'string' &&\n\t\t\t\t\t\t\tpostType.icon.startsWith( 'dashicons-' )\n\t\t\t\t\t\t\t\t? postType.icon.slice( 10 )\n\t\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\t// We need to keep track of naming conflicts. If a conflict\n\t// occurs, we need to add slug.\n\tconst templateLabels = useMemo(\n\t\t() =>\n\t\t\tpublicPostTypes?.reduce( ( accumulator, { labels } ) => {\n\t\t\t\tconst templateName = (\n\t\t\t\t\tlabels.template_name || labels.singular_name\n\t\t\t\t).toLowerCase();\n\t\t\t\taccumulator[ templateName ] =\n\t\t\t\t\t( accumulator[ templateName ] || 0 ) + 1;\n\t\t\t\treturn accumulator;\n\t\t\t}, {} ),\n\t\t[ publicPostTypes ]\n\t);\n\tconst needsUniqueIdentifier = useCallback(\n\t\t( { labels, slug } ) => {\n\t\t\tconst templateName = (\n\t\t\t\tlabels.template_name || labels.singular_name\n\t\t\t).toLowerCase();\n\t\t\treturn templateLabels[ templateName ] > 1 && templateName !== slug;\n\t\t},\n\t\t[ templateLabels ]\n\t);\n\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 =\n\t\t\t\tlabels.template_name ||\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t\t__( 'Single item: %s' ),\n\t\t\t\t\tlabels.singular_name\n\t\t\t\t);\n\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\tmenuItemTitle = labels.template_name\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t// translators: 1: Name of the template e.g: \"Single Item: Post\". 2: Slug of the post type e.g: \"book\".\n\t\t\t\t\t\t\t_x( '%1$s (%2$s)', 'post type menu label' ),\n\t\t\t\t\t\t\tlabels.template_name,\n\t\t\t\t\t\t\tslug\n\t\t\t\t\t )\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t// translators: 1: Name of the post type e.g: \"Post\". 2: Slug of the post type e.g: \"book\".\n\t\t\t\t\t\t\t_x(\n\t\t\t\t\t\t\t\t'Single item: %1$s (%2$s)',\n\t\t\t\t\t\t\t\t'post type menu label'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\t\t\tslug\n\t\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:\n\t\t\t\t\t\t\ttypeof icon === 'string' &&\n\t\t\t\t\t\t\ticon.startsWith( 'dashicons-' )\n\t\t\t\t\t\t\t\t? icon.slice( 10 )\n\t\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\tconst templateSlug = `${ templatePrefixes[ slug ] }-${ suggestion.slug }`;\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\ttitle: templateSlug,\n\t\t\t\t\t\t\t\t\tslug: templateSlug,\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 templateName = (\n\t\t\t\tlabels.template_name || labels.singular_name\n\t\t\t).toLowerCase();\n\t\t\taccumulator[ templateName ] =\n\t\t\t\t( accumulator[ templateName ] || 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 templateName = (\n\t\t\tlabels.template_name || labels.singular_name\n\t\t).toLowerCase();\n\t\treturn taxonomyLabels[ templateName ] > 1 && templateName !== 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.template_name || labels.singular_name;\n\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\tmenuItemTitle = labels.template_name\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t// translators: 1: Name of the template e.g: \"Products by Category\". 2: Slug of the taxonomy e.g: \"product_cat\".\n\t\t\t\t\t\t\t_x( '%1$s (%2$s)', 'taxonomy template menu label' ),\n\t\t\t\t\t\t\tlabels.template_name,\n\t\t\t\t\t\t\tslug\n\t\t\t\t\t )\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t// translators: 1: Name of the taxonomy e.g: \"Category\". 2: Slug of the taxonomy e.g: \"product_cat\".\n\t\t\t\t\t\t\t_x( '%1$s (%2$s)', 'taxonomy menu label' ),\n\t\t\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\t\t\tslug\n\t\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\tconst templateSlug = `${ templatePrefixes[ slug ] }-${ suggestion.slug }`;\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\ttitle: templateSlug,\n\t\t\t\t\t\t\t\t\tslug: templateSlug,\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\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\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 templateSlug = `author-${ suggestion.slug }`;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttitle: templateSlug,\n\t\t\t\t\t\t\tslug: templateSlug,\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 = EMPTY_OBJECT\n) => {\n\tconst recordsToExcludePerEntity = useTemplatesToExclude(\n\t\tentityName,\n\t\ttemplatePrefixes,\n\t\tadditionalQueryParameters\n\t);\n\tconst entitiesHasRecords = 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 ] = !! select(\n\t\t\t\t\t\tcoreStore\n\t\t\t\t\t).getEntityRecords( entityName, slug, {\n\t\t\t\t\t\tper_page: 1,\n\t\t\t\t\t\t_fields: 'id',\n\t\t\t\t\t\tcontext: 'view',\n\t\t\t\t\t\texclude: existingEntitiesIds,\n\t\t\t\t\t\t...additionalQueryParameters[ slug ],\n\t\t\t\t\t} )?.length;\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[\n\t\t\ttemplatePrefixes,\n\t\t\trecordsToExcludePerEntity,\n\t\t\tentityName,\n\t\t\tadditionalQueryParameters,\n\t\t]\n\t);\n\tconst entitiesInfo = useMemo( () => {\n\t\treturn Object.keys( templatePrefixes || {} ).reduce(\n\t\t\t( accumulator, slug ) => {\n\t\t\t\tconst existingEntitiesIds =\n\t\t\t\t\trecordsToExcludePerEntity?.[ slug ]?.map(\n\t\t\t\t\t\t( { id } ) => id\n\t\t\t\t\t) || [];\n\t\t\t\taccumulator[ slug ] = {\n\t\t\t\t\thasEntities: entitiesHasRecords[ slug ],\n\t\t\t\t\texistingEntitiesIds,\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, recordsToExcludePerEntity, entitiesHasRecords ] );\n\treturn entitiesInfo;\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,OAAO,EAAEC,WAAW,QAAQ,oBAAoB;AACzD,SAASC,EAAE,EAAEC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AACjD,SAASC,SAAS,EAAEC,IAAI,EAAEC,OAAO,QAAQ,kBAAkB;;AAE3D;AACA;AACA;AACA,SAASC,kBAAkB,QAAQ,uBAAuB;AAE1D,MAAMC,YAAY,GAAG,CAAC,CAAC;;AAEvB;AACA;AACA;AACA;AACA;;AAEA,MAAMC,sBAAsB,GAAGA,CAAEC,MAAM,EAAEC,IAAI,KAAM;EAClD,IAAIC,KAAK,GAAGF,MAAM;EAClBC,IAAI,CAACE,KAAK,CAAE,GAAI,CAAC,CAACC,OAAO,CAAIC,SAAS,IAAM;IAC3CH,KAAK,GAAGA,KAAK,GAAIG,SAAS,CAAE;EAC7B,CAAE,CAAC;EACH,OAAOH,KAAK;AACb,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMI,kBAAkB,GAAGA,CAAEC,QAAQ,EAAEN,IAAI,KAAM;EACvD,OAAO,CAAEM,QAAQ,IAAI,EAAE,EAAGC,GAAG,CAAIC,MAAM,KAAQ;IAC9C,GAAGA,MAAM;IACTC,IAAI,E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AC,EACD,CAAC,CACF,CAAC;EACF,CAAC,EACD,CACCoB,gBAAgB,EAChBgE,yBAAyB,EACzBH,UAAU,EACVC,yBAAyB,CAE3B,CAAC;EACD,MAAMQ,YAAY,GAAGhJ,OAAO,CAAE,MAAM;IACnC,OAAO8H,MAAM,CAACgB,IAAI,CAAEpE,gBAAgB,IAAI,CAAC,CAAE,CAAC,CAACrB,MAAM,CAClD,CAAEC,WAAW,EAAEnB,IAAI,KAAM;MACxB,MAAMgE,mBAAmB,GACxBuC,yBAAyB,GAAIvG,IAAI,CAAE,EAAEhB,GAAG,CACvC,CAAE;QAAE4H;MAAG,CAAC,KAAMA,EACf,CAAC,IAAI,EAAE;MACRzF,WAAW,CAAEnB,IAAI,CAAE,GAAG;QACrBqD,WAAW,EAAEqD,kBAAkB,CAAE1G,IAAI,CAAE;QACvCgE;MACD,CAAC;MACD,OAAO7C,WAAW;IACnB,CAAC,EACD,CAAC,CACF,CAAC;EACF,CAAC,EAAE,CAAEoB,gBAAgB,EAAEgE,yBAAyB,EAAEG,kBAAkB,CAAG,CAAC;EACxE,OAAOG,YAAY;AACpB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["useSelect","store","coreStore","decodeEntities","useMemo","useCallback","__","_x","sprintf","blockMeta","post","archive","safeDecodeURI","TEMPLATE_POST_TYPE","EMPTY_OBJECT","getValueFromObjectPath","object","path","value","split","forEach","fieldName","prefixSlug","prefix","slug","mapToIHasNameAndId","entities","map","entity","name","useExistingTemplates","select","getEntityRecords","per_page","useDefaultTemplateTypes","getCurrentTheme","default_template_types","usePublicPostTypes","postTypes","getPostTypes","excludedPostTypes","filter","viewable","includes","sort","a","b","localeCompare","usePublicTaxonomies","taxonomies","getTaxonomies","visibility","publicly_queryable","usePostTypeArchiveMenuItems","publicPostTypes","postTypesWithArchives","postType","has_archive","existingTemplates","postTypeLabels","reduce","accumulator","labels","singularName","singular_name","toLowerCase","needsUniqueIdentifier","some","existingTemplate","title","description","icon","startsWith","slice","templatePrefix","usePostTypeMenuItems","onClickMenuItem","defaultTemplateTypes","templateLabels","templateName","template_name","templatePrefixes","suffix","postTypesInfo","useEntitiesInfo","menuItems","generalTemplateSlug","defaultTemplateType","find","_slug","_needsUniqueIdentifier","menuItemTitle","menuItem","hasEntities","onClick","template","type","config","recordNamePath","queryArgs","search","_fields","orderBy","exclude","existingEntitiesIds","getSpecificTemplate","suggestion","templateSlug","push","postTypesMenuItems","key","defaultPostTypesMenuItems","useTaxonomiesMenuItems","publicTaxonomies","taxonomyLabels","taxonomiesInfo","existingTemplateSlugs","taxonomy","hasGeneralTemplate","taxonomiesMenuItems","defaultTaxonomiesMenuItems","USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX","user","USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS","who","useAuthorMenuItem","authorInfo","authorMenuItem","search_items","not_found","all_items","entityName","additionalQueryParameters","entitiesHasRecords","Object","keys","context","length","entitiesInfo"],"sources":["@wordpress/edit-site/src/components/add-new-template/utils.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useMemo, useCallback } from '@wordpress/element';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { blockMeta, post, archive } from '@wordpress/icons';\nimport { safeDecodeURI } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { TEMPLATE_POST_TYPE } from '../../utils/constants';\n\nconst EMPTY_OBJECT = {};\n\n/**\n * @typedef IHasNameAndId\n * @property {string|number} id The entity's id.\n * @property {string} name The entity's name.\n */\n\nconst getValueFromObjectPath = ( object, path ) => {\n\tlet value = object;\n\tpath.split( '.' ).forEach( ( fieldName ) => {\n\t\tvalue = value?.[ fieldName ];\n\t} );\n\treturn value;\n};\n\n/**\n * Helper that adds a prefix to a post slug. The slug needs to be URL-decoded first,\n * so that we have raw Unicode characters there. The server will truncate the slug to\n * 200 characters, respecing Unicode char boundary. On the other hand, the server\n * doesn't detect urlencoded octet boundary and can possibly construct slugs that\n * are not valid urlencoded strings.\n * @param {string} prefix The prefix to add to the slug.\n * @param {string} slug The slug to add the prefix to.\n * @return {string} The slug with the prefix.\n */\nfunction prefixSlug( prefix, slug ) {\n\treturn `${ prefix }-${ safeDecodeURI( slug ) }`;\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 entities 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( getValueFromObjectPath( 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(\n\t\t\t\t'postType',\n\t\t\t\tTEMPLATE_POST_TYPE,\n\t\t\t\t{\n\t\t\t\t\tper_page: -1,\n\t\t\t\t}\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( coreStore ).getCurrentTheme()?.default_template_types || [],\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\n\t\t\t?.filter(\n\t\t\t\t( { viewable, slug } ) =>\n\t\t\t\t\tviewable && ! excludedPostTypes.includes( slug )\n\t\t\t)\n\t\t\t.sort( ( a, b ) => {\n\t\t\t\t// Sort post types alphabetically by name,\n\t\t\t\t// but exclude the built-in 'post' type from sorting.\n\t\t\t\tif ( a.slug === 'post' || b.slug === 'post' ) {\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\n\t\t\t\treturn a.name.localeCompare( b.name );\n\t\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 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\t// We need to keep track of naming conflicts. If a conflict\n\t// occurs, we need to add slug.\n\tconst postTypeLabels = useMemo(\n\t\t() =>\n\t\t\tpublicPostTypes?.reduce( ( accumulator, { labels } ) => {\n\t\t\t\tconst singularName = labels.singular_name.toLowerCase();\n\t\t\t\taccumulator[ singularName ] =\n\t\t\t\t\t( accumulator[ singularName ] || 0 ) + 1;\n\t\t\t\treturn accumulator;\n\t\t\t}, {} ),\n\t\t[ publicPostTypes ]\n\t);\n\tconst needsUniqueIdentifier = 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\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 latest 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:\n\t\t\t\t\t\t\ttypeof postType.icon === 'string' &&\n\t\t\t\t\t\t\tpostType.icon.startsWith( 'dashicons-' )\n\t\t\t\t\t\t\t\t? postType.icon.slice( 10 )\n\t\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 defaultTemplateTypes = useDefaultTemplateTypes();\n\t// We need to keep track of naming conflicts. If a conflict\n\t// occurs, we need to add slug.\n\tconst templateLabels = useMemo(\n\t\t() =>\n\t\t\tpublicPostTypes?.reduce( ( accumulator, { labels } ) => {\n\t\t\t\tconst templateName = (\n\t\t\t\t\tlabels.template_name || labels.singular_name\n\t\t\t\t).toLowerCase();\n\t\t\t\taccumulator[ templateName ] =\n\t\t\t\t\t( accumulator[ templateName ] || 0 ) + 1;\n\t\t\t\treturn accumulator;\n\t\t\t}, {} ),\n\t\t[ publicPostTypes ]\n\t);\n\tconst needsUniqueIdentifier = useCallback(\n\t\t( { labels, slug } ) => {\n\t\t\tconst templateName = (\n\t\t\t\tlabels.template_name || labels.singular_name\n\t\t\t).toLowerCase();\n\t\t\treturn templateLabels[ templateName ] > 1 && templateName !== slug;\n\t\t},\n\t\t[ templateLabels ]\n\t);\n\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 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 _needsUniqueIdentifier = needsUniqueIdentifier( postType );\n\t\t\tlet menuItemTitle =\n\t\t\t\tlabels.template_name ||\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t\t__( 'Single item: %s' ),\n\t\t\t\t\tlabels.singular_name\n\t\t\t\t);\n\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\tmenuItemTitle = labels.template_name\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t// translators: 1: Name of the template e.g: \"Single Item: Post\". 2: Slug of the post type e.g: \"book\".\n\t\t\t\t\t\t\t_x( '%1$s (%2$s)', 'post type menu label' ),\n\t\t\t\t\t\t\tlabels.template_name,\n\t\t\t\t\t\t\tslug\n\t\t\t\t\t )\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t// translators: 1: Name of the post type e.g: \"Post\". 2: Slug of the post type e.g: \"book\".\n\t\t\t\t\t\t\t_x(\n\t\t\t\t\t\t\t\t'Single item: %1$s (%2$s)',\n\t\t\t\t\t\t\t\t'post type menu label'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\t\t\tslug\n\t\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:\n\t\t\t\t\t\t\ttypeof icon === 'string' &&\n\t\t\t\t\t\t\ticon.startsWith( 'dashicons-' )\n\t\t\t\t\t\t\t\t? icon.slice( 10 )\n\t\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\tconst templateSlug = prefixSlug(\n\t\t\t\t\t\t\t\t\ttemplatePrefixes[ slug ],\n\t\t\t\t\t\t\t\t\tsuggestion.slug\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: templateSlug,\n\t\t\t\t\t\t\t\t\tslug: templateSlug,\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\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 entities.\n\t\t\tif ( 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 templateName = (\n\t\t\t\tlabels.template_name || labels.singular_name\n\t\t\t).toLowerCase();\n\t\t\taccumulator[ templateName ] =\n\t\t\t\t( accumulator[ templateName ] || 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 templateName = (\n\t\t\tlabels.template_name || labels.singular_name\n\t\t).toLowerCase();\n\t\treturn taxonomyLabels[ templateName ] > 1 && templateName !== 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.template_name || labels.singular_name;\n\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\tmenuItemTitle = labels.template_name\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t// translators: 1: Name of the template e.g: \"Products by Category\". 2: Slug of the taxonomy e.g: \"product_cat\".\n\t\t\t\t\t\t\t_x( '%1$s (%2$s)', 'taxonomy template menu label' ),\n\t\t\t\t\t\t\tlabels.template_name,\n\t\t\t\t\t\t\tslug\n\t\t\t\t\t )\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t// translators: 1: Name of the taxonomy e.g: \"Category\". 2: Slug of the taxonomy e.g: \"product_cat\".\n\t\t\t\t\t\t\t_x( '%1$s (%2$s)', 'taxonomy menu label' ),\n\t\t\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\t\t\tslug\n\t\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\tconst templateSlug = prefixSlug(\n\t\t\t\t\t\t\t\t\ttemplatePrefixes[ slug ],\n\t\t\t\t\t\t\t\t\tsuggestion.slug\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: templateSlug,\n\t\t\t\t\t\t\t\t\tslug: templateSlug,\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\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\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 templateSlug = prefixSlug(\n\t\t\t\t\t\t\t'author',\n\t\t\t\t\t\t\tsuggestion.slug\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttitle: sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: Name of the author e.g: \"Admin\".\n\t\t\t\t\t\t\t\t__( 'Author: %s' ),\n\t\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tslug: templateSlug,\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 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 = EMPTY_OBJECT\n) => {\n\tconst entitiesHasRecords = 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\taccumulator[ slug ] = !! select(\n\t\t\t\t\t\tcoreStore\n\t\t\t\t\t).getEntityRecords( entityName, slug, {\n\t\t\t\t\t\tper_page: 1,\n\t\t\t\t\t\t_fields: 'id',\n\t\t\t\t\t\tcontext: 'view',\n\t\t\t\t\t\t...additionalQueryParameters[ slug ],\n\t\t\t\t\t} )?.length;\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, entityName, additionalQueryParameters ]\n\t);\n\tconst entitiesInfo = useMemo( () => {\n\t\treturn Object.keys( templatePrefixes || {} ).reduce(\n\t\t\t( accumulator, slug ) => {\n\t\t\t\taccumulator[ slug ] = {\n\t\t\t\t\thasEntities: entitiesHasRecords[ slug ],\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, entitiesHasRecords ] );\n\treturn entitiesInfo;\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,OAAO,EAAEC,WAAW,QAAQ,oBAAoB;AACzD,SAASC,EAAE,EAAEC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AACjD,SAASC,SAAS,EAAEC,IAAI,EAAEC,OAAO,QAAQ,kBAAkB;AAC3D,SAASC,aAAa,QAAQ,gBAAgB;;AAE9C;AACA;AACA;AACA,SAASC,kBAAkB,QAAQ,uBAAuB;AAE1D,MAAMC,YAAY,GAAG,CAAC,CAAC;;AAEvB;AACA;AACA;AACA;AACA;;AAEA,MAAMC,sBAAsB,GAAGA,CAAEC,MAAM,EAAEC,IAAI,KAAM;EAClD,IAAIC,KAAK,GAAGF,MAAM;EAClBC,IAAI,CAACE,KAAK,CAAE,GAAI,CAAC,CAACC,OAAO,CAAIC,SAAS,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AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM3C,eAAe,GAAGA,CACvB+C,UAAU,EACVlD,gBAAgB,EAChBmD,yBAAyB,GAAGtH,YAAY,KACpC;EACJ,MAAMuH,kBAAkB,GAAGrI,SAAS,CACjC+B,MAAM,IAAM;IACb,OAAOuG,MAAM,CAACC,IAAI,CAAEtD,gBAAgB,IAAI,CAAC,CAAE,CAAC,CAACrB,MAAM,CAClD,CAAEC,WAAW,EAAErC,IAAI,KAAM;MACxBqC,WAAW,CAAErC,IAAI,CAAE,GAAG,CAAC,CAAEO,MAAM,CAC9B7B,SACD,CAAC,CAAC8B,gBAAgB,CAAEmG,UAAU,EAAE3G,IAAI,EAAE;QACrCS,QAAQ,EAAE,CAAC;QACXoE,OAAO,EAAE,IAAI;QACbmC,OAAO,EAAE,MAAM;QACf,GAAGJ,yBAAyB,CAAE5G,IAAI;MACnC,CAAE,CAAC,EAAEiH,MAAM;MACX,OAAO5E,WAAW;IACnB,CAAC,EACD,CAAC,CACF,CAAC;EACF,CAAC,EACD,CAAEoB,gBAAgB,EAAEkD,UAAU,EAAEC,yBAAyB,CAC1D,CAAC;EACD,MAAMM,YAAY,GAAGtI,OAAO,CAAE,MAAM;IACnC,OAAOkI,MAAM,CAACC,IAAI,CAAEtD,gBAAgB,IAAI,CAAC,CAAE,CAAC,CAACrB,MAAM,CAClD,CAAEC,WAAW,EAAErC,IAAI,KAAM;MACxBqC,WAAW,CAAErC,IAAI,CAAE,GAAG;QACrBqE,WAAW,EAAEwC,kBAAkB,CAAE7G,IAAI;MACtC,CAAC;MACD,OAAOqC,WAAW;IACnB,CAAC,EACD,CAAC,CACF,CAAC;EACF,CAAC,EAAE,CAAEoB,gBAAgB,EAAEoD,kBAAkB,CAAG,CAAC;EAC7C,OAAOK,YAAY;AACpB,CAAC","ignoreList":[]}
@@ -5,6 +5,8 @@ import { __ } from '@wordpress/i18n';
5
5
  import { edit } from '@wordpress/icons';
6
6
  import { useMemo } from '@wordpress/element';
7
7
  import { privateApis as routerPrivateApis } from '@wordpress/router';
8
+ import { useDispatch, useSelect } from '@wordpress/data';
9
+ import { store as coreStore } from '@wordpress/core-data';
8
10
 
9
11
  /**
10
12
  * Internal dependencies
@@ -14,6 +16,53 @@ import { unlock } from '../../lock-unlock';
14
16
  const {
15
17
  useHistory
16
18
  } = unlock(routerPrivateApis);
19
+ export const useSetActiveTemplateAction = () => {
20
+ const {
21
+ getEntityRecord
22
+ } = useSelect(coreStore);
23
+ const {
24
+ editEntityRecord,
25
+ saveEditedEntityRecord
26
+ } = useDispatch(coreStore);
27
+ return useMemo(() => ({
28
+ id: 'set-active-template',
29
+ label(items) {
30
+ return items.some(item => item._isActive) ? __('Deactivate') : __('Activate');
31
+ },
32
+ isPrimary: true,
33
+ icon: edit,
34
+ isEligible(item) {
35
+ return !(item.slug === 'index' && item.source === 'theme');
36
+ },
37
+ async callback(items) {
38
+ var _await$getEntityRecor;
39
+ const deactivate = items.some(item => item._isActive);
40
+ // current active templates
41
+ const activeTemplates = {
42
+ ...((_await$getEntityRecor = await getEntityRecord('root', 'site').active_templates) !== null && _await$getEntityRecor !== void 0 ? _await$getEntityRecor : {})
43
+ };
44
+ for (const item of items) {
45
+ if (deactivate) {
46
+ if (item.source === 'theme') {
47
+ activeTemplates[item.slug] = false;
48
+ } else {
49
+ delete activeTemplates[item.slug];
50
+ }
51
+ } else {
52
+ activeTemplates[item.slug] = item.id;
53
+ }
54
+ }
55
+ // To do: figure out why the REST API deletes the option when
56
+ // it's set to an empty object. That would trigger the migration
57
+ // function, which will make all templates in the database active.
58
+ activeTemplates.__preventCollapse = 0;
59
+ await editEntityRecord('root', 'site', undefined, {
60
+ active_templates: activeTemplates
61
+ });
62
+ await saveEditedEntityRecord('root', 'site');
63
+ }
64
+ }), [editEntityRecord, saveEditedEntityRecord, getEntityRecord]);
65
+ };
17
66
  export const useEditPostAction = () => {
18
67
  const history = useHistory();
19
68
  return useMemo(() => ({