@wordpress/edit-site 4.9.0 → 4.10.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 (105) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/add-new-template/add-custom-generic-template-modal.js +84 -0
  3. package/build/components/add-new-template/add-custom-generic-template-modal.js.map +1 -0
  4. package/build/components/add-new-template/add-custom-template-modal.js +92 -53
  5. package/build/components/add-new-template/add-custom-template-modal.js.map +1 -1
  6. package/build/components/add-new-template/new-template.js +77 -81
  7. package/build/components/add-new-template/new-template.js.map +1 -1
  8. package/build/components/add-new-template/utils.js +310 -44
  9. package/build/components/add-new-template/utils.js.map +1 -1
  10. package/build/components/code-editor/index.js +17 -4
  11. package/build/components/code-editor/index.js.map +1 -1
  12. package/build/components/editor/index.js +16 -0
  13. package/build/components/editor/index.js.map +1 -1
  14. package/build/components/error-boundary/index.js +6 -0
  15. package/build/components/error-boundary/index.js.map +1 -1
  16. package/build/components/global-styles/dimensions-panel.js +2 -6
  17. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  18. package/build/components/global-styles/global-styles-provider.js +4 -2
  19. package/build/components/global-styles/global-styles-provider.js.map +1 -1
  20. package/build/components/global-styles/hooks.js +10 -1
  21. package/build/components/global-styles/hooks.js.map +1 -1
  22. package/build/components/global-styles/screen-color-palette.js +13 -17
  23. package/build/components/global-styles/screen-color-palette.js.map +1 -1
  24. package/build/components/global-styles/screen-colors.js +9 -1
  25. package/build/components/global-styles/screen-colors.js.map +1 -1
  26. package/build/components/global-styles/screen-link-color.js +48 -14
  27. package/build/components/global-styles/screen-link-color.js.map +1 -1
  28. package/build/components/global-styles/use-global-styles-output.js +171 -33
  29. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  30. package/build/components/global-styles/utils.js +1 -1
  31. package/build/components/global-styles/utils.js.map +1 -1
  32. package/build/components/keyboard-shortcut-help-modal/index.js +1 -3
  33. package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  34. package/build/components/template-details/edit-template-title.js +11 -3
  35. package/build/components/template-details/edit-template-title.js.map +1 -1
  36. package/build/components/template-details/index.js +1 -20
  37. package/build/components/template-details/index.js.map +1 -1
  38. package/build/store/selectors.js +4 -1
  39. package/build/store/selectors.js.map +1 -1
  40. package/build-module/components/add-new-template/add-custom-generic-template-modal.js +77 -0
  41. package/build-module/components/add-new-template/add-custom-generic-template-modal.js.map +1 -0
  42. package/build-module/components/add-new-template/add-custom-template-modal.js +92 -53
  43. package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -1
  44. package/build-module/components/add-new-template/new-template.js +80 -83
  45. package/build-module/components/add-new-template/new-template.js.map +1 -1
  46. package/build-module/components/add-new-template/utils.js +286 -40
  47. package/build-module/components/add-new-template/utils.js.map +1 -1
  48. package/build-module/components/code-editor/index.js +18 -5
  49. package/build-module/components/code-editor/index.js.map +1 -1
  50. package/build-module/components/editor/index.js +16 -0
  51. package/build-module/components/editor/index.js.map +1 -1
  52. package/build-module/components/error-boundary/index.js +5 -0
  53. package/build-module/components/error-boundary/index.js.map +1 -1
  54. package/build-module/components/global-styles/dimensions-panel.js +2 -6
  55. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  56. package/build-module/components/global-styles/global-styles-provider.js +4 -2
  57. package/build-module/components/global-styles/global-styles-provider.js.map +1 -1
  58. package/build-module/components/global-styles/hooks.js +10 -1
  59. package/build-module/components/global-styles/hooks.js.map +1 -1
  60. package/build-module/components/global-styles/screen-color-palette.js +14 -19
  61. package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
  62. package/build-module/components/global-styles/screen-colors.js +9 -1
  63. package/build-module/components/global-styles/screen-colors.js.map +1 -1
  64. package/build-module/components/global-styles/screen-link-color.js +47 -14
  65. package/build-module/components/global-styles/screen-link-color.js.map +1 -1
  66. package/build-module/components/global-styles/use-global-styles-output.js +171 -35
  67. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  68. package/build-module/components/global-styles/utils.js +2 -2
  69. package/build-module/components/global-styles/utils.js.map +1 -1
  70. package/build-module/components/keyboard-shortcut-help-modal/index.js +1 -2
  71. package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  72. package/build-module/components/template-details/edit-template-title.js +12 -3
  73. package/build-module/components/template-details/edit-template-title.js.map +1 -1
  74. package/build-module/components/template-details/index.js +2 -21
  75. package/build-module/components/template-details/index.js.map +1 -1
  76. package/build-module/store/selectors.js +5 -2
  77. package/build-module/store/selectors.js.map +1 -1
  78. package/build-style/style-rtl.css +21 -23
  79. package/build-style/style.css +21 -23
  80. package/package.json +29 -29
  81. package/src/components/add-new-template/add-custom-generic-template-modal.js +97 -0
  82. package/src/components/add-new-template/add-custom-template-modal.js +92 -58
  83. package/src/components/add-new-template/new-template.js +142 -94
  84. package/src/components/add-new-template/style.scss +21 -0
  85. package/src/components/add-new-template/utils.js +290 -46
  86. package/src/components/code-editor/index.js +15 -5
  87. package/src/components/editor/index.js +11 -0
  88. package/src/components/error-boundary/index.js +5 -0
  89. package/src/components/global-styles/dimensions-panel.js +2 -7
  90. package/src/components/global-styles/global-styles-provider.js +8 -9
  91. package/src/components/global-styles/hooks.js +15 -0
  92. package/src/components/global-styles/screen-color-palette.js +25 -27
  93. package/src/components/global-styles/screen-colors.js +9 -3
  94. package/src/components/global-styles/screen-link-color.js +65 -23
  95. package/src/components/global-styles/style.scss +7 -11
  96. package/src/components/global-styles/test/use-global-styles-output.js +168 -0
  97. package/src/components/global-styles/use-global-styles-output.js +234 -59
  98. package/src/components/global-styles/utils.js +2 -2
  99. package/src/components/keyboard-shortcut-help-modal/index.js +1 -2
  100. package/src/components/keyboard-shortcut-help-modal/style.scss +0 -5
  101. package/src/components/list/style.scss +0 -8
  102. package/src/components/template-details/edit-template-title.js +10 -2
  103. package/src/components/template-details/index.js +4 -21
  104. package/src/components/test/error-boundary.js +38 -0
  105. package/src/store/selectors.js +11 -5
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["filter","includes","DropdownMenu","MenuGroup","MenuItem","NavigableMenu","useState","useSelect","useDispatch","store","coreStore","editorStore","archive","blockMeta","category","home","list","media","notFound","page","post","postAuthor","postDate","search","tag","__","sprintf","noticesStore","AddCustomTemplateModal","usePostTypes","usePostTypesEntitiesInfo","useHistory","editSiteStore","DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","single","index","author","taxonomy","date","attachment","NewTemplate","postType","history","postTypes","showCustomTemplateModal","setShowCustomTemplateModal","entityForSuggestions","setEntityForSuggestions","existingTemplates","defaultTemplateTypes","select","getEntityRecords","per_page","__experimentalGetDefaultTemplateTypes","postTypesEntitiesInfo","saveEntityRecord","createErrorNotice","setTemplate","createTemplate","template","title","description","slug","newTemplate","toString","status","is_wp_suggestion","throwOnError","id","push","postId","type","error","errorMessage","message","code","existingTemplateSlugs","map","missingTemplates","extraTemplates","reduce","accumulator","_postType","labels","icon","hasGeneralTemplate","hasEntities","menuItem","singular_name","startsWith","slice","onClick","postsToExclude","existingPosts","length","sort","template1","template2","indexOf","add_new","add_new_item","noArrow","variant"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,MAAT,EAAiBC,QAAjB,QAAiC,QAAjC;AAEA;AACA;AACA;;AACA,SACCC,YADD,EAECC,SAFD,EAGCC,QAHD,EAICC,aAJD,QAKO,uBALP;AAMA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SAASD,KAAK,IAAIE,WAAlB,QAAqC,mBAArC;AACA,SACCC,OADD,EAECC,SAFD,EAGCC,QAHD,EAICC,IAJD,EAKCC,IALD,EAMCC,KAND,EAOCC,QAPD,EAQCC,IARD,EASCC,IATD,EAUCC,UAVD,EAWCC,QAXD,EAYCC,MAZD,EAaCC,GAbD,QAcO,kBAdP;AAeA,SAASC,EAAT,EAAaC,OAAb,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AuB,IACxB,cAAC,sBAAD;AACC,IAAA,OAAO,EAAG,MAAMC,0BAA0B,CAAE,KAAF,CAD3C;AAEC,IAAA,QAAQ,EAAGa,cAFZ;AAGC,IAAA,oBAAoB,EAAGZ;AAHxB,IAjDF,CADD;AA0DA","sourcesContent":["/**\n * External dependencies\n */\nimport { filter, includes } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tNavigableMenu,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as editorStore } from '@wordpress/editor';\nimport {\n\tarchive,\n\tblockMeta,\n\tcategory,\n\thome,\n\tlist,\n\tmedia,\n\tnotFound,\n\tpage,\n\tpost,\n\tpostAuthor,\n\tpostDate,\n\tsearch,\n\ttag,\n} from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport AddCustomTemplateModal from './add-custom-template-modal';\nimport { usePostTypes, usePostTypesEntitiesInfo } from './utils';\nimport { useHistory } from '../routes';\nimport { store as editSiteStore } from '../../store';\n\nconst DEFAULT_TEMPLATE_SLUGS = [\n\t'front-page',\n\t'single',\n\t'page',\n\t'index',\n\t'archive',\n\t'author',\n\t'category',\n\t'date',\n\t'tag',\n\t'taxonomy',\n\t'search',\n\t'404',\n];\n\nconst TEMPLATE_ICONS = {\n\t'front-page': home,\n\tsingle: post,\n\tpage,\n\tarchive,\n\tsearch,\n\t404: notFound,\n\tindex: list,\n\tcategory,\n\tauthor: postAuthor,\n\ttaxonomy: blockMeta,\n\tdate: postDate,\n\ttag,\n\tattachment: media,\n};\n\nexport default function NewTemplate( { postType } ) {\n\tconst history = useHistory();\n\tconst postTypes = usePostTypes();\n\tconst [ showCustomTemplateModal, setShowCustomTemplateModal ] =\n\t\tuseState( false );\n\tconst [ entityForSuggestions, setEntityForSuggestions ] = useState( {} );\n\tconst { existingTemplates, defaultTemplateTypes } = useSelect(\n\t\t( select ) => ( {\n\t\t\texistingTemplates: select( coreStore ).getEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{ per_page: -1 }\n\t\t\t),\n\t\t\tdefaultTemplateTypes:\n\t\t\t\tselect( editorStore ).__experimentalGetDefaultTemplateTypes(),\n\t\t} ),\n\t\t[]\n\t);\n\tconst postTypesEntitiesInfo = usePostTypesEntitiesInfo( existingTemplates );\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst { setTemplate } = useDispatch( editSiteStore );\n\n\tasync function createTemplate( template ) {\n\t\ttry {\n\t\t\tconst { title, description, slug } = template;\n\t\t\tconst newTemplate = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tdescription,\n\t\t\t\t\t// Slugs need to be strings, so this is for template `404`\n\t\t\t\t\tslug: slug.toString(),\n\t\t\t\t\tstatus: 'publish',\n\t\t\t\t\ttitle,\n\t\t\t\t\t// This adds a post meta field in template that is part of `is_custom` value calculation.\n\t\t\t\t\tis_wp_suggestion: true,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\t// Set template before navigating away to avoid initial stale value.\n\t\t\tsetTemplate( newTemplate.id, newTemplate.slug );\n\n\t\t\t// Navigate to the created template editor.\n\t\t\thistory.push( {\n\t\t\t\tpostId: newTemplate.id,\n\t\t\t\tpostType: newTemplate.type,\n\t\t\t} );\n\n\t\t\t// TODO: Add a success notice?\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while creating the template.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t}\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst missingTemplates = filter(\n\t\tdefaultTemplateTypes,\n\t\t( template ) =>\n\t\t\tincludes( DEFAULT_TEMPLATE_SLUGS, template.slug ) &&\n\t\t\t! includes( existingTemplateSlugs, template.slug )\n\t);\n\n\tconst extraTemplates = ( postTypes || [] ).reduce(\n\t\t( accumulator, _postType ) => {\n\t\t\tconst { slug, labels, icon } = _postType;\n\t\t\tconst hasGeneralTemplate = existingTemplateSlugs?.includes(\n\t\t\t\t`single-${ slug }`\n\t\t\t);\n\t\t\tconst hasEntities = postTypesEntitiesInfo?.[ slug ]?.hasEntities;\n\t\t\tconst menuItem = {\n\t\t\t\tslug: `single-${ slug }`,\n\t\t\t\ttitle: sprintf(\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\t\tdescription: sprintf(\n\t\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t\t__( 'Displays a single item: %s.' ),\n\t\t\t\t\tlabels.singular_name\n\t\t\t\t),\n\t\t\t\t// `icon` is the `menu_icon` property of a post type. We\n\t\t\t\t// only handle `dashicons` for now, even if the `menu_icon`\n\t\t\t\t// also supports urls and svg as values.\n\t\t\t\ticon: icon?.startsWith( 'dashicons-' )\n\t\t\t\t\t? icon.slice( 10 )\n\t\t\t\t\t: null,\n\t\t\t};\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\tsetShowCustomTemplateModal( true );\n\t\t\t\t\tsetEntityForSuggestions( {\n\t\t\t\t\t\ttype: 'postType',\n\t\t\t\t\t\tslug,\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\tpostsToExclude:\n\t\t\t\t\t\t\tpostTypesEntitiesInfo[ slug ].existingPosts,\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\tif ( ! missingTemplates.length && ! extraTemplates.length ) {\n\t\treturn null;\n\t}\n\t// Update the sort order to match the DEFAULT_TEMPLATE_SLUGS order.\n\tmissingTemplates?.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\t// Append all extra templates at the end of the list for now.\n\tmissingTemplates.push( ...extraTemplates );\n\treturn (\n\t\t<>\n\t\t\t<DropdownMenu\n\t\t\t\tclassName=\"edit-site-new-template-dropdown\"\n\t\t\t\ticon={ null }\n\t\t\t\ttext={ postType.labels.add_new }\n\t\t\t\tlabel={ postType.labels.add_new_item }\n\t\t\t\tpopoverProps={ {\n\t\t\t\t\tnoArrow: false,\n\t\t\t\t} }\n\t\t\t\ttoggleProps={ {\n\t\t\t\t\tvariant: 'primary',\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ () => (\n\t\t\t\t\t<NavigableMenu className=\"edit-site-new-template-dropdown__popover\">\n\t\t\t\t\t\t<MenuGroup label={ postType.labels.add_new_item }>\n\t\t\t\t\t\t\t{ missingTemplates.map( ( template ) => {\n\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t\t\tonClick,\n\t\t\t\t\t\t\t\t\ticon,\n\t\t\t\t\t\t\t\t} = template;\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\t\t\ticon ||\n\t\t\t\t\t\t\t\t\t\t\tTEMPLATE_ICONS[ slug ] ||\n\t\t\t\t\t\t\t\t\t\t\tpost\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\t\tinfo={ description }\n\t\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t\tonClick\n\t\t\t\t\t\t\t\t\t\t\t\t? onClick( template )\n\t\t\t\t\t\t\t\t\t\t\t\t: createTemplate( template )\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ title }\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t</NavigableMenu>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t\t{ showCustomTemplateModal && (\n\t\t\t\t<AddCustomTemplateModal\n\t\t\t\t\tonClose={ () => setShowCustomTemplateModal( false ) }\n\t\t\t\t\tonSelect={ createTemplate }\n\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["DropdownMenu","MenuGroup","MenuItem","NavigableMenu","useState","useDispatch","store","coreStore","archive","blockMeta","category","home","list","media","notFound","page","post","postAuthor","postDate","search","tag","layout","customGenericTemplateIcon","__","noticesStore","AddCustomTemplateModal","useExistingTemplates","useDefaultTemplateTypes","entitiesConfig","usePostTypes","usePostTypePage","useTaxonomies","useTaxonomyCategory","useTaxonomyTag","useExtraTemplates","AddCustomGenericTemplateModal","useHistory","editSiteStore","DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","single","index","author","taxonomy","date","attachment","NewTemplate","postType","showCustomTemplateModal","setShowCustomTemplateModal","showCustomGenericTemplateModal","setShowCustomGenericTemplateModal","entityForSuggestions","setEntityForSuggestions","history","saveEntityRecord","createErrorNotice","setTemplate","createTemplate","template","isWPSuggestion","title","description","slug","newTemplate","toString","status","is_wp_suggestion","throwOnError","id","push","postId","type","error","errorMessage","message","code","missingTemplates","useMissingTemplates","length","labels","add_new","add_new_item","noArrow","variant","map","onClick","icon","postTypes","pagePostType","taxonomies","categoryTaxonomy","tagTaxonomy","existingTemplates","defaultTemplateTypes","existingTemplateSlugs","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","categoryMenuItem","tagMenuItem","pageMenuItem","enhancedMissingDefaultTemplateTypes","forEach","menuItem","matchIndex","findIndex","splice","sort","template1","template2","indexOf","extraPostTypeTemplates","extraTaxonomyTemplates"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,YADD,EAECC,SAFD,EAGCC,QAHD,EAICC,aAJD,QAKO,uBALP;AAMA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,WAAT,QAA4B,iBAA5B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SACCC,OADD,EAECC,SAFD,EAGCC,QAHD,EAICC,IAJD,EAKCC,IALD,EAMCC,KAND,EAOCC,QAPD,EAQCC,IARD,EASCC,IATD,EAUCC,UAVD,EAWCC,QAXD,EAYCC,MAZD,EAaCC,GAbD,EAcCC,MAAM,IAAIC,yBAdX,QAeO,kBAfP;AAgBA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASjB,KAAK,IAAIkB,YAAlB,QAAsC,oBAAtC;AAEA;AACA;AACA;;AACA,OAAOC,sBAAP,MAAmC,6BAAnC;AACA,SACCC,oBADD,EAECC,uBAFD,EAGCC,cAHD,E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C,SAAb,KAA4B;AACtE,WACC1E,sBAAsB,CAAC2E,OAAvB,CAAgCF,SAAS,CAAChD,IAA1C,IACAzB,sBAAsB,CAAC2E,OAAvB,CAAgCD,SAAS,CAACjD,IAA1C,CAFD;AAIA,GALD;AAMA,QAAMmD,sBAAsB,GAAGhF,iBAAiB,CAC/CsD,SAD+C,EAE/C5D,cAAc,CAACmB,QAFgC,EAG/CoD,eAH+C,CAAhD;AAKA,QAAMgB,sBAAsB,GAAGjF,iBAAiB,CAC/CwD,UAD+C,EAE/C9D,cAAc,CAACe,QAFgC,EAG/CwD,eAH+C,CAAhD;AAKA,QAAMtB,gBAAgB,GAAG,CACxB,GAAG2B,mCADqB,EAExB,GAAGU,sBAFqB,EAGxB,GAAGC,sBAHqB,CAAzB;AAKA,SAAOtC,gBAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tNavigableMenu,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tarchive,\n\tblockMeta,\n\tcategory,\n\thome,\n\tlist,\n\tmedia,\n\tnotFound,\n\tpage,\n\tpost,\n\tpostAuthor,\n\tpostDate,\n\tsearch,\n\ttag,\n\tlayout as customGenericTemplateIcon,\n} from '@wordpress/icons';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport AddCustomTemplateModal from './add-custom-template-modal';\nimport {\n\tuseExistingTemplates,\n\tuseDefaultTemplateTypes,\n\tentitiesConfig,\n\tusePostTypes,\n\tusePostTypePage,\n\tuseTaxonomies,\n\tuseTaxonomyCategory,\n\tuseTaxonomyTag,\n\tuseExtraTemplates,\n} from './utils';\nimport AddCustomGenericTemplateModal from './add-custom-generic-template-modal';\nimport { useHistory } from '../routes';\nimport { store as editSiteStore } from '../../store';\n\nconst DEFAULT_TEMPLATE_SLUGS = [\n\t'front-page',\n\t'single',\n\t'page',\n\t'index',\n\t'archive',\n\t'author',\n\t'category',\n\t'date',\n\t'tag',\n\t'taxonomy',\n\t'search',\n\t'404',\n];\n\nconst TEMPLATE_ICONS = {\n\t'front-page': home,\n\tsingle: post,\n\tpage,\n\tarchive,\n\tsearch,\n\t404: notFound,\n\tindex: list,\n\tcategory,\n\tauthor: postAuthor,\n\ttaxonomy: blockMeta,\n\tdate: postDate,\n\ttag,\n\tattachment: media,\n};\n\nexport default function NewTemplate( { postType } ) {\n\tconst [ showCustomTemplateModal, setShowCustomTemplateModal ] =\n\t\tuseState( false );\n\tconst [\n\t\tshowCustomGenericTemplateModal,\n\t\tsetShowCustomGenericTemplateModal,\n\t] = useState( false );\n\tconst [ entityForSuggestions, setEntityForSuggestions ] = useState( {} );\n\n\tconst history = useHistory();\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst { setTemplate } = useDispatch( editSiteStore );\n\n\tasync function createTemplate( template, isWPSuggestion = true ) {\n\t\ttry {\n\t\t\tconst { title, description, slug } = template;\n\t\t\tconst newTemplate = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tdescription,\n\t\t\t\t\t// Slugs need to be strings, so this is for template `404`\n\t\t\t\t\tslug: slug.toString(),\n\t\t\t\t\tstatus: 'publish',\n\t\t\t\t\ttitle,\n\t\t\t\t\t// This adds a post meta field in template that is part of `is_custom` value calculation.\n\t\t\t\t\tis_wp_suggestion: isWPSuggestion,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\t// Set template before navigating away to avoid initial stale value.\n\t\t\tsetTemplate( newTemplate.id, newTemplate.slug );\n\n\t\t\t// Navigate to the created template editor.\n\t\t\thistory.push( {\n\t\t\t\tpostId: newTemplate.id,\n\t\t\t\tpostType: newTemplate.type,\n\t\t\t} );\n\n\t\t\t// TODO: Add a success notice?\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while creating the template.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t}\n\n\tconst missingTemplates = useMissingTemplates(\n\t\tsetEntityForSuggestions,\n\t\tsetShowCustomTemplateModal\n\t);\n\tif ( ! missingTemplates.length ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<>\n\t\t\t<DropdownMenu\n\t\t\t\tclassName=\"edit-site-new-template-dropdown\"\n\t\t\t\ticon={ null }\n\t\t\t\ttext={ postType.labels.add_new }\n\t\t\t\tlabel={ postType.labels.add_new_item }\n\t\t\t\tpopoverProps={ {\n\t\t\t\t\tnoArrow: false,\n\t\t\t\t} }\n\t\t\t\ttoggleProps={ {\n\t\t\t\t\tvariant: 'primary',\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ () => (\n\t\t\t\t\t<NavigableMenu className=\"edit-site-new-template-dropdown__popover\">\n\t\t\t\t\t\t<MenuGroup label={ postType.labels.add_new_item }>\n\t\t\t\t\t\t\t{ missingTemplates.map( ( template ) => {\n\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t\t\tonClick,\n\t\t\t\t\t\t\t\t\ticon,\n\t\t\t\t\t\t\t\t} = template;\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\t\t\ticon ||\n\t\t\t\t\t\t\t\t\t\t\tTEMPLATE_ICONS[ slug ] ||\n\t\t\t\t\t\t\t\t\t\t\tpost\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\t\tinfo={ description }\n\t\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t\tonClick\n\t\t\t\t\t\t\t\t\t\t\t\t? onClick( template )\n\t\t\t\t\t\t\t\t\t\t\t\t: createTemplate( template )\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ title }\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\ticon={ customGenericTemplateIcon }\n\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\tinfo={ __(\n\t\t\t\t\t\t\t\t\t'Custom templates can be applied to any post or page.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tkey=\"custom-template\"\n\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\tsetShowCustomGenericTemplateModal( true )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Custom template' ) }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t</NavigableMenu>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t\t{ showCustomTemplateModal && (\n\t\t\t\t<AddCustomTemplateModal\n\t\t\t\t\tonClose={ () => setShowCustomTemplateModal( false ) }\n\t\t\t\t\tonSelect={ createTemplate }\n\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showCustomGenericTemplateModal && (\n\t\t\t\t<AddCustomGenericTemplateModal\n\t\t\t\t\tonClose={ () => setShowCustomGenericTemplateModal( false ) }\n\t\t\t\t\tcreateTemplate={ createTemplate }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction useMissingTemplates(\n\tsetEntityForSuggestions,\n\tsetShowCustomTemplateModal\n) {\n\tconst postTypes = usePostTypes();\n\tconst pagePostType = usePostTypePage();\n\tconst taxonomies = useTaxonomies();\n\tconst categoryTaxonomy = useTaxonomyCategory();\n\tconst tagTaxonomy = useTaxonomyTag();\n\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\n\tconst missingDefaultTemplates = ( defaultTemplateTypes || [] ).filter(\n\t\t( template ) =>\n\t\t\tDEFAULT_TEMPLATE_SLUGS.includes( template.slug ) &&\n\t\t\t! existingTemplateSlugs.includes( template.slug )\n\t);\n\tconst onClickMenuItem = ( _entityForSuggestions ) => {\n\t\tsetShowCustomTemplateModal( true );\n\t\tsetEntityForSuggestions( _entityForSuggestions );\n\t};\n\t// TODO: find better names for these variables. `useExtraTemplates` returns an array of items.\n\tconst categoryMenuItem = useExtraTemplates(\n\t\tcategoryTaxonomy,\n\t\tentitiesConfig.category,\n\t\tonClickMenuItem\n\t);\n\tconst tagMenuItem = useExtraTemplates(\n\t\ttagTaxonomy,\n\t\tentitiesConfig.tag,\n\t\tonClickMenuItem\n\t);\n\tconst pageMenuItem = useExtraTemplates(\n\t\tpagePostType,\n\t\tentitiesConfig.page,\n\t\tonClickMenuItem\n\t);\n\t// We need to replace existing default template types with\n\t// the create specific template functionality. The original\n\t// info (title, description, etc.) is preserved in the\n\t// `useExtraTemplates` hook.\n\tconst enhancedMissingDefaultTemplateTypes = [ ...missingDefaultTemplates ];\n\t[ categoryMenuItem, tagMenuItem, pageMenuItem ].forEach( ( menuItem ) => {\n\t\tif ( ! menuItem?.length ) {\n\t\t\treturn;\n\t\t}\n\t\tconst matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(\n\t\t\t( template ) => template.slug === menuItem[ 0 ].slug\n\t\t);\n\t\t// Some default template types might have been filtered above from\n\t\t// `missingDefaultTemplates` because they only check for the general\n\t\t// template. So here we either replace or append the item, augmented\n\t\t// with the check if it has available specific item to create a\n\t\t// template for.\n\t\tif ( matchIndex > -1 ) {\n\t\t\tenhancedMissingDefaultTemplateTypes.splice(\n\t\t\t\tmatchIndex,\n\t\t\t\t1,\n\t\t\t\tmenuItem[ 0 ]\n\t\t\t);\n\t\t} else {\n\t\t\tenhancedMissingDefaultTemplateTypes.push( menuItem[ 0 ] );\n\t\t}\n\t} );\n\t// Update the sort order to match the DEFAULT_TEMPLATE_SLUGS order.\n\tenhancedMissingDefaultTemplateTypes?.sort( ( template1, template2 ) => {\n\t\treturn (\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template1.slug ) -\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template2.slug )\n\t\t);\n\t} );\n\tconst extraPostTypeTemplates = useExtraTemplates(\n\t\tpostTypes,\n\t\tentitiesConfig.postType,\n\t\tonClickMenuItem\n\t);\n\tconst extraTaxonomyTemplates = useExtraTemplates(\n\t\ttaxonomies,\n\t\tentitiesConfig.taxonomy,\n\t\tonClickMenuItem\n\t);\n\tconst missingTemplates = [\n\t\t...enhancedMissingDefaultTemplateTypes,\n\t\t...extraPostTypeTemplates,\n\t\t...extraTaxonomyTemplates,\n\t];\n\treturn missingTemplates;\n}\n"]}
@@ -8,69 +8,257 @@ import { get } from 'lodash';
8
8
 
9
9
  import { useSelect } from '@wordpress/data';
10
10
  import { store as coreStore } from '@wordpress/core-data';
11
+ import { store as editorStore } from '@wordpress/editor';
11
12
  import { decodeEntities } from '@wordpress/html-entities';
12
13
  import { useMemo } from '@wordpress/element';
13
- export const usePostTypes = () => {
14
+ import { __, sprintf } from '@wordpress/i18n';
15
+ import { blockMeta, post } from '@wordpress/icons';
16
+ /**
17
+ * @typedef IHasNameAndId
18
+ * @property {string|number} id The entity's id.
19
+ * @property {string} name The entity's name.
20
+ */
21
+
22
+ /**
23
+ * Helper util to map records to add a `name` prop from a
24
+ * provided path, in order to handle all entities in the same
25
+ * fashion(implementing`IHasNameAndId` interface).
26
+ *
27
+ * @param {Object[]} entities The array of entities.
28
+ * @param {string} path The path to map a `name` property from the entity.
29
+ * @return {IHasNameAndId[]} An array of enitities that now implement the `IHasNameAndId` interface.
30
+ */
31
+
32
+ export const mapToIHasNameAndId = (entities, path) => {
33
+ return (entities || []).map(entity => ({ ...entity,
34
+ name: decodeEntities(get(entity, path))
35
+ }));
36
+ };
37
+ /**
38
+ * @typedef {Object} EntitiesInfo
39
+ * @property {boolean} hasEntities If an entity has available records(posts, terms, etc..).
40
+ * @property {number[]} existingEntitiesIds An array of the existing entities ids.
41
+ */
42
+
43
+ /**
44
+ * @typedef {Object} EntityConfig
45
+ * @property {string} entityName The entity's name.
46
+ * @property {Function} getOrderBy Getter for an entity's `orderBy` query parameter, given the object
47
+ * {search} as argument.
48
+ * @property {Function} getIcon Getter function for returning an entity's icon for the menu item.
49
+ * @property {Function} getTitle Getter function for returning an entity's title for the menu item.
50
+ * @property {Function} getDescription Getter function for returning an entity's description for the menu item.
51
+ * @property {string} recordNamePath The path to an entity's properties to use as a `name`. If not provided
52
+ * is assumed that `name` property exists.
53
+ * @property {string} templatePrefix The template prefix to create new templates and check against existing
54
+ * templates. For example custom post types need a `single-` prefix to all
55
+ * templates(`single-post-hello`), whereas `pages` don't (`page-hello`).
56
+ * @property {string} templateSlug If this property is provided, it is going to be used for the creation of
57
+ * new templates and the check against existing templates in the place
58
+ * of the actual entity's `slug`. An example is `Tag` templates where the
59
+ * the Tag's taxonomy slug is `post_tag`, but template hierarchy is based
60
+ * on `tag` alias.
61
+ */
62
+
63
+ const taxonomyBaseConfig = {
64
+ entityName: 'taxonomy',
65
+ getOrderBy: _ref => {
66
+ let {
67
+ search
68
+ } = _ref;
69
+ return search ? 'name' : 'count';
70
+ },
71
+ getIcon: () => blockMeta,
72
+ getTitle: labels => sprintf( // translators: %s: Name of the taxonomy e.g: "Cagegory".
73
+ __('Single taxonomy: %s'), labels.singular_name),
74
+ getDescription: labels => sprintf( // translators: %s: Name of the taxonomy e.g: "Product Categories".
75
+ __('Displays a single taxonomy: %s.'), labels.singular_name)
76
+ };
77
+ const postTypeBaseConfig = {
78
+ entityName: 'postType',
79
+ getOrderBy: _ref2 => {
80
+ let {
81
+ search
82
+ } = _ref2;
83
+ return search ? 'relevance' : 'modified';
84
+ },
85
+ recordNamePath: 'title.rendered',
86
+ // `icon` is the `menu_icon` property of a post type. We
87
+ // only handle `dashicons` for now, even if the `menu_icon`
88
+ // also supports urls and svg as values.
89
+ getIcon: _icon => _icon !== null && _icon !== void 0 && _icon.startsWith('dashicons-') ? _icon.slice(10) : post,
90
+ getTitle: labels => sprintf( // translators: %s: Name of the post type e.g: "Post".
91
+ __('Single item: %s'), labels.singular_name),
92
+ getDescription: labels => sprintf( // translators: %s: Name of the post type e.g: "Post".
93
+ __('Displays a single item: %s.'), labels.singular_name)
94
+ };
95
+ export const entitiesConfig = {
96
+ postType: { ...postTypeBaseConfig,
97
+ templatePrefix: 'single-'
98
+ },
99
+ page: { ...postTypeBaseConfig
100
+ },
101
+ taxonomy: { ...taxonomyBaseConfig,
102
+ templatePrefix: 'taxonomy-'
103
+ },
104
+ category: { ...taxonomyBaseConfig
105
+ },
106
+ tag: { ...taxonomyBaseConfig,
107
+ templateSlug: 'tag'
108
+ }
109
+ };
110
+ export const useExistingTemplates = () => {
111
+ return useSelect(select => select(coreStore).getEntityRecords('postType', 'wp_template', {
112
+ per_page: -1
113
+ }), []);
114
+ };
115
+ export const useDefaultTemplateTypes = () => {
116
+ return useSelect(select => select(editorStore).__experimentalGetDefaultTemplateTypes(), []);
117
+ };
118
+
119
+ const usePublicPostTypes = () => {
14
120
  const postTypes = useSelect(select => select(coreStore).getPostTypes({
15
121
  per_page: -1
16
122
  }), []);
17
123
  return useMemo(() => {
18
- const excludedPostTypes = ['attachment', 'page'];
19
- return postTypes === null || postTypes === void 0 ? void 0 : postTypes.filter(_ref => {
124
+ const excludedPostTypes = ['attachment'];
125
+ return postTypes === null || postTypes === void 0 ? void 0 : postTypes.filter(_ref3 => {
20
126
  let {
21
127
  viewable,
22
128
  slug
23
- } = _ref;
129
+ } = _ref3;
24
130
  return viewable && !excludedPostTypes.includes(slug);
25
131
  });
26
132
  }, [postTypes]);
133
+ }; // `page` post type is a special case in the template hierarchy,
134
+ // so we exclude it from the list of post types and we handle it
135
+ // separately.
136
+
137
+
138
+ export const usePostTypes = () => {
139
+ const postTypes = usePublicPostTypes();
140
+ return useMemo(() => {
141
+ return postTypes === null || postTypes === void 0 ? void 0 : postTypes.filter(_ref4 => {
142
+ let {
143
+ slug
144
+ } = _ref4;
145
+ return slug !== 'page';
146
+ });
147
+ }, [postTypes]);
148
+ };
149
+ export const usePostTypePage = () => {
150
+ const postTypes = usePublicPostTypes();
151
+ return useMemo(() => {
152
+ return postTypes === null || postTypes === void 0 ? void 0 : postTypes.filter(_ref5 => {
153
+ let {
154
+ slug
155
+ } = _ref5;
156
+ return slug === 'page';
157
+ });
158
+ }, [postTypes]);
159
+ };
160
+
161
+ const usePublicTaxonomies = () => {
162
+ const taxonomies = useSelect(select => select(coreStore).getTaxonomies({
163
+ per_page: -1
164
+ }), []);
165
+ return useMemo(() => {
166
+ return taxonomies === null || taxonomies === void 0 ? void 0 : taxonomies.filter(_ref6 => {
167
+ let {
168
+ visibility
169
+ } = _ref6;
170
+ return visibility === null || visibility === void 0 ? void 0 : visibility.publicly_queryable;
171
+ });
172
+ }, [taxonomies]);
27
173
  };
28
174
  /**
29
- * @typedef {Object} PostTypeEntitiesInfo
30
- * @property {boolean} hasEntities If a postType has available entities.
31
- * @property {number[]} existingPosts An array of the existing entities ids.
175
+ * `category` and `post_tag` are handled specifically in template
176
+ * hierarchy so we need to differentiate them and return the rest,
177
+ * e.g. `category-$slug` and `taxonomy-$taxonomy-$term`.
32
178
  */
33
179
 
180
+
181
+ export const useTaxonomies = () => {
182
+ const taxonomies = usePublicTaxonomies();
183
+ const specialTaxonomies = ['category', 'post_tag'];
184
+ return useMemo(() => taxonomies === null || taxonomies === void 0 ? void 0 : taxonomies.filter(_ref7 => {
185
+ let {
186
+ slug
187
+ } = _ref7;
188
+ return !specialTaxonomies.includes(slug);
189
+ }), [taxonomies]);
190
+ };
191
+ export const useTaxonomyCategory = () => {
192
+ const taxonomies = usePublicTaxonomies();
193
+ return useMemo(() => taxonomies === null || taxonomies === void 0 ? void 0 : taxonomies.filter(_ref8 => {
194
+ let {
195
+ slug
196
+ } = _ref8;
197
+ return slug === 'category';
198
+ }), [taxonomies]);
199
+ };
200
+ export const useTaxonomyTag = () => {
201
+ const taxonomies = usePublicTaxonomies();
202
+ return useMemo(() => taxonomies === null || taxonomies === void 0 ? void 0 : taxonomies.filter(_ref9 => {
203
+ let {
204
+ slug
205
+ } = _ref9;
206
+ return slug === 'post_tag';
207
+ }), [taxonomies]);
208
+ };
34
209
  /**
35
- * Helper hook that returns information about a post type having
36
- * posts that we can create a specific template for.
210
+ * Helper hook that returns information about an entity having
211
+ * records that we can create a specific template for.
212
+ *
213
+ * For example we can search for `terms` in `taxonomy` entity or
214
+ * `posts` in `postType` entity.
37
215
  *
38
- * First we need to find the existing posts with an associated template,
39
- * to query afterwards for any remaing post, by excluding them.
216
+ * First we need to find the existing records with an associated template,
217
+ * to query afterwards for any remaing record, by excluding them.
40
218
  *
41
- * @param {string[]} existingTemplates The existing templates.
42
- * @return {Record<string,PostTypeEntitiesInfo>} An object with the postTypes as `keys` and PostTypeEntitiesInfo as values.
219
+ * @param {string[]} existingTemplates The existing templates.
220
+ * @param {Object[]} entities The array of entities we need to get extra information.
221
+ * @param {EntityConfig} entityConfig The entity config.
222
+ * @return {Record<string,EntitiesInfo>} An object with the `entities.slug` as `keys` and EntitiesInfo as values.
43
223
  */
44
224
 
45
- export const usePostTypesEntitiesInfo = existingTemplates => {
46
- const postTypes = usePostTypes();
225
+ const useEntitiesInfo = (existingTemplates, entities, _ref10) => {
226
+ let {
227
+ entityName,
228
+ templatePrefix,
229
+ templateSlug
230
+ } = _ref10;
47
231
  const slugsToExcludePerEntity = useMemo(() => {
48
- return postTypes === null || postTypes === void 0 ? void 0 : postTypes.reduce((accumulator, _postType) => {
49
- const slugsWithTemplates = (existingTemplates || []).reduce((_accumulator, existingTemplate) => {
50
- const prefix = `single-${_postType.slug}-`;
232
+ return entities === null || entities === void 0 ? void 0 : entities.reduce((accumulator, entity) => {
233
+ let _prefix = `${templateSlug || entity.slug}-`;
51
234
 
52
- if (existingTemplate.slug.startsWith(prefix)) {
53
- _accumulator.push(existingTemplate.slug.substring(prefix.length));
235
+ if (templatePrefix) {
236
+ _prefix = templatePrefix + _prefix;
237
+ }
238
+
239
+ const slugsWithTemplates = (existingTemplates || []).reduce((_accumulator, existingTemplate) => {
240
+ if (existingTemplate.slug.startsWith(_prefix)) {
241
+ _accumulator.push(existingTemplate.slug.substring(_prefix.length));
54
242
  }
55
243
 
56
244
  return _accumulator;
57
245
  }, []);
58
246
 
59
247
  if (slugsWithTemplates.length) {
60
- accumulator[_postType.slug] = slugsWithTemplates;
248
+ accumulator[entity.slug] = slugsWithTemplates;
61
249
  }
62
250
 
63
251
  return accumulator;
64
252
  }, {});
65
- }, [postTypes, existingTemplates]);
66
- const postsToExcludePerEntity = useSelect(select => {
253
+ }, [entities, existingTemplates]);
254
+ const recordsToExcludePerEntity = useSelect(select => {
67
255
  if (!slugsToExcludePerEntity) {
68
256
  return;
69
257
  }
70
258
 
71
- const postsToExclude = Object.entries(slugsToExcludePerEntity).reduce((accumulator, _ref2) => {
72
- let [slug, slugsWithTemplates] = _ref2;
73
- const postsWithTemplates = select(coreStore).getEntityRecords('postType', slug, {
259
+ return Object.entries(slugsToExcludePerEntity).reduce((accumulator, _ref11) => {
260
+ let [slug, slugsWithTemplates] = _ref11;
261
+ const postsWithTemplates = select(coreStore).getEntityRecords(entityName, slug, {
74
262
  _fields: 'id',
75
263
  context: 'view',
76
264
  slug: slugsWithTemplates
@@ -82,38 +270,96 @@ export const usePostTypesEntitiesInfo = existingTemplates => {
82
270
 
83
271
  return accumulator;
84
272
  }, {});
85
- return postsToExclude;
86
273
  }, [slugsToExcludePerEntity]);
87
274
  const entitiesInfo = useSelect(select => {
88
- return postTypes === null || postTypes === void 0 ? void 0 : postTypes.reduce((accumulator, _ref3) => {
89
- var _postsToExcludePerEnt, _select$getEntityReco;
275
+ return entities === null || entities === void 0 ? void 0 : entities.reduce((accumulator, _ref12) => {
276
+ var _recordsToExcludePerE, _select$getEntityReco;
90
277
 
91
278
  let {
92
279
  slug
93
- } = _ref3;
94
- const existingPosts = (postsToExcludePerEntity === null || postsToExcludePerEntity === void 0 ? void 0 : (_postsToExcludePerEnt = postsToExcludePerEntity[slug]) === null || _postsToExcludePerEnt === void 0 ? void 0 : _postsToExcludePerEnt.map(_ref4 => {
280
+ } = _ref12;
281
+ const existingEntitiesIds = (recordsToExcludePerEntity === null || recordsToExcludePerEntity === void 0 ? void 0 : (_recordsToExcludePerE = recordsToExcludePerEntity[slug]) === null || _recordsToExcludePerE === void 0 ? void 0 : _recordsToExcludePerE.map(_ref13 => {
95
282
  let {
96
283
  id
97
- } = _ref4;
284
+ } = _ref13;
98
285
  return id;
99
286
  })) || [];
100
287
  accumulator[slug] = {
101
- hasEntities: !!((_select$getEntityReco = select(coreStore).getEntityRecords('postType', slug, {
288
+ hasEntities: !!((_select$getEntityReco = select(coreStore).getEntityRecords(entityName, slug, {
102
289
  per_page: 1,
103
290
  _fields: 'id',
104
291
  context: 'view',
105
- exclude: existingPosts
292
+ exclude: existingEntitiesIds
106
293
  })) !== null && _select$getEntityReco !== void 0 && _select$getEntityReco.length),
107
- existingPosts
294
+ existingEntitiesIds
108
295
  };
109
296
  return accumulator;
110
297
  }, {});
111
- }, [postTypes, postsToExcludePerEntity]);
298
+ }, [entities, recordsToExcludePerEntity]);
112
299
  return entitiesInfo;
113
300
  };
114
- export const mapToIHasNameAndId = (entities, path) => {
115
- return (entities || []).map(entity => ({ ...entity,
116
- name: decodeEntities(get(entity, path))
117
- }));
301
+
302
+ export const useExtraTemplates = (entities, entityConfig, onClickMenuItem) => {
303
+ const existingTemplates = useExistingTemplates();
304
+ const defaultTemplateTypes = useDefaultTemplateTypes();
305
+ const entitiesInfo = useEntitiesInfo(existingTemplates, entities, entityConfig);
306
+ const existingTemplateSlugs = (existingTemplates || []).map(_ref14 => {
307
+ let {
308
+ slug
309
+ } = _ref14;
310
+ return slug;
311
+ });
312
+ const extraTemplates = (entities || []).reduce((accumulator, entity) => {
313
+ var _entityConfig$getIcon, _entitiesInfo$slug;
314
+
315
+ const {
316
+ slug,
317
+ labels,
318
+ icon
319
+ } = entity;
320
+ const slugForGeneralTemplate = entityConfig.templateSlug || slug; // We need to check if the general template is part of the
321
+ // defaultTemplateTypes. If it is, just use that info and
322
+ // augment it with the specific template functionality.
323
+
324
+ const defaultTemplateType = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref15 => {
325
+ let {
326
+ slug: _slug
327
+ } = _ref15;
328
+ return _slug === slugForGeneralTemplate;
329
+ });
330
+ const generalTemplateSlug = (defaultTemplateType === null || defaultTemplateType === void 0 ? void 0 : defaultTemplateType.slug) || `${entityConfig.templatePrefix}${slug}`;
331
+ const hasGeneralTemplate = existingTemplateSlugs === null || existingTemplateSlugs === void 0 ? void 0 : existingTemplateSlugs.includes(generalTemplateSlug);
332
+ const menuItem = defaultTemplateType ? { ...defaultTemplateType
333
+ } : {
334
+ slug: generalTemplateSlug,
335
+ title: entityConfig.getTitle(labels),
336
+ description: entityConfig.getDescription(labels),
337
+ icon: (_entityConfig$getIcon = entityConfig.getIcon) === null || _entityConfig$getIcon === void 0 ? void 0 : _entityConfig$getIcon.call(entityConfig, icon)
338
+ };
339
+ const hasEntities = entitiesInfo === null || entitiesInfo === void 0 ? void 0 : (_entitiesInfo$slug = entitiesInfo[slug]) === null || _entitiesInfo$slug === void 0 ? void 0 : _entitiesInfo$slug.hasEntities; // We have a different template creation flow only if they have entities.
340
+
341
+ if (hasEntities) {
342
+ menuItem.onClick = template => {
343
+ onClickMenuItem({
344
+ type: entityConfig.entityName,
345
+ slug,
346
+ config: entityConfig,
347
+ labels,
348
+ hasGeneralTemplate,
349
+ template,
350
+ postsToExclude: entitiesInfo[slug].existingEntitiesIds
351
+ });
352
+ };
353
+ } // We don't need to add the menu item if there are no
354
+ // entities and the general template exists.
355
+
356
+
357
+ if (!hasGeneralTemplate || hasEntities) {
358
+ accumulator.push(menuItem);
359
+ }
360
+
361
+ return accumulator;
362
+ }, []);
363
+ return extraTemplates;
118
364
  };
119
365
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/utils.js"],"names":["get","useSelect","store","coreStore","decodeEntities","useMemo","usePostTypes","postTypes","select","getPostTypes","per_page","excludedPostTypes","filter","viewable","slug","includes","usePostTypesEntitiesInfo","existingTemplates","slugsToExcludePerEntity","reduce","accumulator","_postType","slugsWithTemplates","_accumulator","existingTemplate","prefix","startsWith","push","substring","length","postsToExcludePerEntity","postsToExclude","Object","entries","postsWithTemplates","getEntityRecords","_fields","context","entitiesInfo","existingPosts","map","id","hasEntities","exclude","mapToIHasNameAndId","entities","path","entity","name"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SAASC,cAAT,QAA+B,0BAA/B;AACA,SAASC,OAAT,QAAwB,oBAAxB;AAEA,OAAO,MAAMC,YAAY,GAAG,MAAM;AACjC,QAAMC,SAAS,GAAGN,SAAS,CACxBO,MAAF,IAAcA,MAAM,CAAEL,SAAF,CAAN,CAAoBM,YAApB,CA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AnC,CACC;AAAA,YAAE;AAAEC,UAAAA;AAAF,SAAF;AAAA,eAAcA,EAAd;AAAA,OADD,MAEK,EAHN;AAIArB,MAAAA,WAAW,CAAEN,IAAF,CAAX,GAAsB;AACrB4B,QAAAA,WAAW,EAAE,CAAC,2BAAElC,MAAM,CAAEL,SAAF,CAAN,CAAoBgC,gBAApB,CACf,UADe,EAEfrB,IAFe,EAGf;AACCJ,UAAAA,QAAQ,EAAE,CADX;AAEC0B,UAAAA,OAAO,EAAE,IAFV;AAGCC,UAAAA,OAAO,EAAE,MAHV;AAICM,UAAAA,OAAO,EAAEJ;AAJV,SAHe,CAAF,kDAAE,sBASbV,MATW,CADO;AAWrBU,QAAAA;AAXqB,OAAtB;AAaA,aAAOnB,WAAP;AACA,KAnBM,EAmBJ,EAnBI,CAAP;AAoBA,GAtB4B,EAuB7B,CAAEb,SAAF,EAAauB,uBAAb,CAvB6B,CAA9B;AAyBA,SAAOQ,YAAP;AACA,CA1EM;AA4EP,OAAO,MAAMM,kBAAkB,GAAG,CAAEC,QAAF,EAAYC,IAAZ,KAAsB;AACvD,SAAO,CAAED,QAAQ,IAAI,EAAd,EAAmBL,GAAnB,CAA0BO,MAAF,KAAgB,EAC9C,GAAGA,MAD2C;AAE9CC,IAAAA,IAAI,EAAE5C,cAAc,CAAEJ,GAAG,CAAE+C,MAAF,EAAUD,IAAV,CAAL;AAF0B,GAAhB,CAAxB,CAAP;AAIA,CALM","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useMemo } from '@wordpress/element';\n\nexport const usePostTypes = () => {\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', 'page' ];\n\t\treturn postTypes?.filter(\n\t\t\t( { viewable, slug } ) =>\n\t\t\t\tviewable && ! excludedPostTypes.includes( slug )\n\t\t);\n\t}, [ postTypes ] );\n};\n\n/**\n * @typedef {Object} PostTypeEntitiesInfo\n * @property {boolean} hasEntities If a postType has available entities.\n * @property {number[]} existingPosts An array of the existing entities ids.\n */\n\n/**\n * Helper hook that returns information about a post type having\n * posts that we can create a specific template for.\n *\n * First we need to find the existing posts with an associated template,\n * to query afterwards for any remaing post, by excluding them.\n *\n * @param {string[]} existingTemplates The existing templates.\n * @return {Record<string,PostTypeEntitiesInfo>} An object with the postTypes as `keys` and PostTypeEntitiesInfo as values.\n */\nexport const usePostTypesEntitiesInfo = ( existingTemplates ) => {\n\tconst postTypes = usePostTypes();\n\tconst slugsToExcludePerEntity = useMemo( () => {\n\t\treturn postTypes?.reduce( ( accumulator, _postType ) => {\n\t\t\tconst slugsWithTemplates = ( existingTemplates || [] ).reduce(\n\t\t\t\t( _accumulator, existingTemplate ) => {\n\t\t\t\t\tconst prefix = `single-${ _postType.slug }-`;\n\t\t\t\t\tif ( existingTemplate.slug.startsWith( prefix ) ) {\n\t\t\t\t\t\t_accumulator.push(\n\t\t\t\t\t\t\texistingTemplate.slug.substring( prefix.length )\n\t\t\t\t\t\t);\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\tif ( slugsWithTemplates.length ) {\n\t\t\t\taccumulator[ _postType.slug ] = slugsWithTemplates;\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t}, {} );\n\t}, [ postTypes, existingTemplates ] );\n\tconst postsToExcludePerEntity = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! slugsToExcludePerEntity ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst postsToExclude = Object.entries(\n\t\t\t\tslugsToExcludePerEntity\n\t\t\t).reduce( ( accumulator, [ slug, slugsWithTemplates ] ) => {\n\t\t\t\tconst postsWithTemplates = select( coreStore ).getEntityRecords(\n\t\t\t\t\t'postType',\n\t\t\t\t\tslug,\n\t\t\t\t\t{\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}\n\t\t\t\t);\n\t\t\t\tif ( postsWithTemplates?.length ) {\n\t\t\t\t\taccumulator[ slug ] = postsWithTemplates;\n\t\t\t\t}\n\t\t\t\treturn accumulator;\n\t\t\t}, {} );\n\t\t\treturn postsToExclude;\n\t\t},\n\t\t[ slugsToExcludePerEntity ]\n\t);\n\tconst entitiesInfo = useSelect(\n\t\t( select ) => {\n\t\t\treturn postTypes?.reduce( ( accumulator, { slug } ) => {\n\t\t\t\tconst existingPosts =\n\t\t\t\t\tpostsToExcludePerEntity?.[ 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: !! select( coreStore ).getEntityRecords(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tper_page: 1,\n\t\t\t\t\t\t\t_fields: 'id',\n\t\t\t\t\t\t\tcontext: 'view',\n\t\t\t\t\t\t\texclude: existingPosts,\n\t\t\t\t\t\t}\n\t\t\t\t\t)?.length,\n\t\t\t\t\texistingPosts,\n\t\t\t\t};\n\t\t\t\treturn accumulator;\n\t\t\t}, {} );\n\t\t},\n\t\t[ postTypes, postsToExcludePerEntity ]\n\t);\n\treturn entitiesInfo;\n};\n\nexport const mapToIHasNameAndId = ( entities, path ) => {\n\treturn ( entities || [] ).map( ( entity ) => ( {\n\t\t...entity,\n\t\tname: decodeEntities( get( entity, path ) ),\n\t} ) );\n};\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/utils.js"],"names":["get","useSelect","store","coreStore","editorStore","decodeEntities","useMemo","__","sprintf","blockMeta","post","mapToIHasNameAndId","entities","path","map","entity","name","taxonomyBaseConfig","entityName","getOrderBy","search","getIcon","getTitle","labels","singular_name","getDescription","postTypeBaseConfig","recordNamePath","_icon","startsWith","slice","entitiesConfig","postType","templatePrefix","page","taxonomy","category","tag","templateSlug","useExistingTemplates","select","getEntityRecords","per_page","useDefaultTemplateTypes","__experimentalGetDefaultTemplateTypes","usePublicPostTypes","postTypes","getPostTypes","excludedPostTypes","filter","viewable","slug","includes","usePostTypes","usePostTypePage","usePublicTaxonomies","taxonomies","getTaxonomies","visibility","publicly_queryable","useTaxonomies","specialTaxonomies","useTaxonomyCategory","useTaxonomyTag","useEntitiesInfo","existingTemplates","slugsToExcludePerEntity","reduce","accumulator","_prefix","slugsWithTemplates","_accumulator","existingTemplate","push","substring","length","recordsToExcludePerEntity","Object","entries","postsWithTemplates","_fields","context","entitiesInfo","existingEntitiesIds","id","hasEntities","exclude","useExtraTemplates","entityConfig","onClickMenuItem","defaultTemplateTypes","existingTemplateSlugs","extraTemplates","icon","slugForGeneralTemplate","defaultTemplateType","find","_slug","generalTemplateSlug","hasGeneralTemplate","menuItem","title","description","onClick","template","type","config","postsToExclude"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SAASD,KAAK,IAAIE,WAAlB,QAAqC,mBAArC;AACA,SAASC,cAAT,QAA+B,0BAA/B;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,SAAT,EAAoBC,IAApB,QAAgC,kBAAhC;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,kBAAkB,GAAG,CAAEC,QAAF,EAAYC,IAAZ,KAAsB;AACvD,SAAO,CAAED,QAAQ,IAAI,EAAd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,QAAK,CAAEgB,kBAAF,IAAwBd,WAA7B,EAA2C;AAC1CjB,MAAAA,WAAW,CAACK,IAAZ,CAAkB2B,QAAlB;AACA;;AACD,WAAOhC,WAAP;AACA,GA7CqB,EA8CtB,EA9CsB,CAAvB;AAgDA,SAAOwB,cAAP;AACA,CAhEM","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useMemo } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { blockMeta, post } from '@wordpress/icons';\n\n/**\n * @typedef IHasNameAndId\n * @property {string|number} id The entity's id.\n * @property {string} name The entity's name.\n */\n\n/**\n * Helper util to map records to add a `name` prop from a\n * provided path, in order to handle all entities in the same\n * fashion(implementing`IHasNameAndId` interface).\n *\n * @param {Object[]} entities The array of entities.\n * @param {string} path The path to map a `name` property from the entity.\n * @return {IHasNameAndId[]} An array of enitities that now implement the `IHasNameAndId` interface.\n */\nexport const mapToIHasNameAndId = ( entities, path ) => {\n\treturn ( entities || [] ).map( ( entity ) => ( {\n\t\t...entity,\n\t\tname: decodeEntities( get( entity, path ) ),\n\t} ) );\n};\n\n/**\n * @typedef {Object} EntitiesInfo\n * @property {boolean} hasEntities If an entity has available records(posts, terms, etc..).\n * @property {number[]} existingEntitiesIds An array of the existing entities ids.\n */\n\n/**\n * @typedef {Object} EntityConfig\n * @property {string} entityName The entity's name.\n * @property {Function} getOrderBy Getter for an entity's `orderBy` query parameter, given the object\n * {search} as argument.\n * @property {Function} getIcon Getter function for returning an entity's icon for the menu item.\n * @property {Function} getTitle Getter function for returning an entity's title for the menu item.\n * @property {Function} getDescription Getter function for returning an entity's description for the menu item.\n * @property {string} recordNamePath The path to an entity's properties to use as a `name`. If not provided\n * is assumed that `name` property exists.\n * @property {string} templatePrefix The template prefix to create new templates and check against existing\n * templates. For example custom post types need a `single-` prefix to all\n * templates(`single-post-hello`), whereas `pages` don't (`page-hello`).\n * @property {string} templateSlug If this property is provided, it is going to be used for the creation of\n * new templates and the check against existing templates in the place\n * of the actual entity's `slug`. An example is `Tag` templates where the\n * the Tag's taxonomy slug is `post_tag`, but template hierarchy is based\n * on `tag` alias.\n */\n\nconst taxonomyBaseConfig = {\n\tentityName: 'taxonomy',\n\tgetOrderBy: ( { search } ) => ( search ? 'name' : 'count' ),\n\tgetIcon: () => blockMeta,\n\tgetTitle: ( labels ) =>\n\t\tsprintf(\n\t\t\t// translators: %s: Name of the taxonomy e.g: \"Cagegory\".\n\t\t\t__( 'Single taxonomy: %s' ),\n\t\t\tlabels.singular_name\n\t\t),\n\tgetDescription: ( labels ) =>\n\t\tsprintf(\n\t\t\t// translators: %s: Name of the taxonomy e.g: \"Product Categories\".\n\t\t\t__( 'Displays a single taxonomy: %s.' ),\n\t\t\tlabels.singular_name\n\t\t),\n};\nconst postTypeBaseConfig = {\n\tentityName: 'postType',\n\tgetOrderBy: ( { search } ) => ( search ? 'relevance' : 'modified' ),\n\trecordNamePath: 'title.rendered',\n\t// `icon` is the `menu_icon` property of a post type. We\n\t// only handle `dashicons` for now, even if the `menu_icon`\n\t// also supports urls and svg as values.\n\tgetIcon: ( _icon ) =>\n\t\t_icon?.startsWith( 'dashicons-' ) ? _icon.slice( 10 ) : post,\n\tgetTitle: ( labels ) =>\n\t\tsprintf(\n\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t__( 'Single item: %s' ),\n\t\t\tlabels.singular_name\n\t\t),\n\tgetDescription: ( labels ) =>\n\t\tsprintf(\n\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t__( 'Displays a single item: %s.' ),\n\t\t\tlabels.singular_name\n\t\t),\n};\nexport const entitiesConfig = {\n\tpostType: {\n\t\t...postTypeBaseConfig,\n\t\ttemplatePrefix: 'single-',\n\t},\n\tpage: { ...postTypeBaseConfig },\n\ttaxonomy: {\n\t\t...taxonomyBaseConfig,\n\t\ttemplatePrefix: 'taxonomy-',\n\t},\n\tcategory: { ...taxonomyBaseConfig },\n\ttag: { ...taxonomyBaseConfig, templateSlug: 'tag' },\n};\n\nexport const useExistingTemplates = () => {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\tper_page: -1,\n\t\t\t} ),\n\t\t[]\n\t);\n};\n\nexport const useDefaultTemplateTypes = () => {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( editorStore ).__experimentalGetDefaultTemplateTypes(),\n\t\t[]\n\t);\n};\n\nconst usePublicPostTypes = () => {\n\tconst postTypes = useSelect(\n\t\t( select ) => select( coreStore ).getPostTypes( { per_page: -1 } ),\n\t\t[]\n\t);\n\treturn useMemo( () => {\n\t\tconst excludedPostTypes = [ 'attachment' ];\n\t\treturn postTypes?.filter(\n\t\t\t( { viewable, slug } ) =>\n\t\t\t\tviewable && ! excludedPostTypes.includes( slug )\n\t\t);\n\t}, [ postTypes ] );\n};\n\n// `page` post type is a special case in the template hierarchy,\n// so we exclude it from the list of post types and we handle it\n// separately.\nexport const usePostTypes = () => {\n\tconst postTypes = usePublicPostTypes();\n\treturn useMemo( () => {\n\t\treturn postTypes?.filter( ( { slug } ) => slug !== 'page' );\n\t}, [ postTypes ] );\n};\nexport const usePostTypePage = () => {\n\tconst postTypes = usePublicPostTypes();\n\treturn useMemo( () => {\n\t\treturn postTypes?.filter( ( { slug } ) => slug === 'page' );\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\n/**\n * `category` and `post_tag` are handled specifically in template\n * hierarchy so we need to differentiate them and return the rest,\n * e.g. `category-$slug` and `taxonomy-$taxonomy-$term`.\n */\nexport const useTaxonomies = () => {\n\tconst taxonomies = usePublicTaxonomies();\n\tconst specialTaxonomies = [ 'category', 'post_tag' ];\n\treturn useMemo(\n\t\t() =>\n\t\t\ttaxonomies?.filter(\n\t\t\t\t( { slug } ) => ! specialTaxonomies.includes( slug )\n\t\t\t),\n\t\t[ taxonomies ]\n\t);\n};\n\nexport const useTaxonomyCategory = () => {\n\tconst taxonomies = usePublicTaxonomies();\n\treturn useMemo(\n\t\t() => taxonomies?.filter( ( { slug } ) => slug === 'category' ),\n\t\t[ taxonomies ]\n\t);\n};\nexport const useTaxonomyTag = () => {\n\tconst taxonomies = usePublicTaxonomies();\n\treturn useMemo(\n\t\t() => taxonomies?.filter( ( { slug } ) => slug === 'post_tag' ),\n\t\t[ taxonomies ]\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 remaing record, by excluding them.\n *\n * @param {string[]} existingTemplates The existing templates.\n * @param {Object[]} entities The array of entities we need to get extra information.\n * @param {EntityConfig} entityConfig The entity config.\n * @return {Record<string,EntitiesInfo>} An object with the `entities.slug` as `keys` and EntitiesInfo as values.\n */\nconst useEntitiesInfo = (\n\texistingTemplates,\n\tentities,\n\t{ entityName, templatePrefix, templateSlug }\n) => {\n\tconst slugsToExcludePerEntity = useMemo( () => {\n\t\treturn entities?.reduce( ( accumulator, entity ) => {\n\t\t\tlet _prefix = `${ templateSlug || entity.slug }-`;\n\t\t\tif ( templatePrefix ) {\n\t\t\t\t_prefix = templatePrefix + _prefix;\n\t\t\t}\n\t\t\tconst slugsWithTemplates = ( existingTemplates || [] ).reduce(\n\t\t\t\t( _accumulator, existingTemplate ) => {\n\t\t\t\t\tif ( existingTemplate.slug.startsWith( _prefix ) ) {\n\t\t\t\t\t\t_accumulator.push(\n\t\t\t\t\t\t\texistingTemplate.slug.substring( _prefix.length )\n\t\t\t\t\t\t);\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\tif ( slugsWithTemplates.length ) {\n\t\t\t\taccumulator[ entity.slug ] = slugsWithTemplates;\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t}, {} );\n\t}, [ entities, existingTemplates ] );\n\tconst recordsToExcludePerEntity = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! slugsToExcludePerEntity ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\treturn Object.entries( slugsToExcludePerEntity ).reduce(\n\t\t\t\t( accumulator, [ slug, slugsWithTemplates ] ) => {\n\t\t\t\t\tconst postsWithTemplates = 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} );\n\t\t\t\t\tif ( postsWithTemplates?.length ) {\n\t\t\t\t\t\taccumulator[ slug ] = postsWithTemplates;\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\tconst entitiesInfo = useSelect(\n\t\t( select ) => {\n\t\t\treturn entities?.reduce( ( 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: !! select( coreStore ).getEntityRecords(\n\t\t\t\t\t\tentityName,\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tper_page: 1,\n\t\t\t\t\t\t\t_fields: 'id',\n\t\t\t\t\t\t\tcontext: 'view',\n\t\t\t\t\t\t\texclude: existingEntitiesIds,\n\t\t\t\t\t\t}\n\t\t\t\t\t)?.length,\n\t\t\t\t\texistingEntitiesIds,\n\t\t\t\t};\n\t\t\t\treturn accumulator;\n\t\t\t}, {} );\n\t\t},\n\t\t[ entities, recordsToExcludePerEntity ]\n\t);\n\treturn entitiesInfo;\n};\n\nexport const useExtraTemplates = (\n\tentities,\n\tentityConfig,\n\tonClickMenuItem\n) => {\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst entitiesInfo = useEntitiesInfo(\n\t\texistingTemplates,\n\t\tentities,\n\t\tentityConfig\n\t);\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst extraTemplates = ( entities || [] ).reduce(\n\t\t( accumulator, entity ) => {\n\t\t\tconst { slug, labels, icon } = entity;\n\t\t\tconst slugForGeneralTemplate = entityConfig.templateSlug || slug;\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 defaultTemplateType = defaultTemplateTypes?.find(\n\t\t\t\t( { slug: _slug } ) => _slug === slugForGeneralTemplate\n\t\t\t);\n\t\t\tconst generalTemplateSlug =\n\t\t\t\tdefaultTemplateType?.slug ||\n\t\t\t\t`${ entityConfig.templatePrefix }${ slug }`;\n\t\t\tconst hasGeneralTemplate =\n\t\t\t\texistingTemplateSlugs?.includes( generalTemplateSlug );\n\t\t\tconst menuItem = defaultTemplateType\n\t\t\t\t? { ...defaultTemplateType }\n\t\t\t\t: {\n\t\t\t\t\t\tslug: generalTemplateSlug,\n\t\t\t\t\t\ttitle: entityConfig.getTitle( labels ),\n\t\t\t\t\t\tdescription: entityConfig.getDescription( labels ),\n\t\t\t\t\t\ticon: entityConfig.getIcon?.( icon ),\n\t\t\t\t };\n\t\t\tconst hasEntities = entitiesInfo?.[ 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: entityConfig.entityName,\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tconfig: entityConfig,\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\tpostsToExclude:\n\t\t\t\t\t\t\tentitiesInfo[ slug ].existingEntitiesIds,\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\treturn extraTemplates;\n};\n"]}
@@ -3,7 +3,7 @@ import { createElement } from "@wordpress/element";
3
3
  /**
4
4
  * WordPress dependencies
5
5
  */
6
- import { parse } from '@wordpress/blocks';
6
+ import { parse, __unstableSerializeAndClean } from '@wordpress/blocks';
7
7
  import { useEntityBlockEditor, useEntityProp } from '@wordpress/core-data';
8
8
  import { useSelect, useDispatch } from '@wordpress/data';
9
9
  import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
@@ -32,10 +32,23 @@ export default function CodeEditor() {
32
32
  };
33
33
  }, []);
34
34
  const [contentStructure, setContent] = useEntityProp('postType', templateType, 'content');
35
- const [blocks,, onChange] = useEntityBlockEditor('postType', templateType);
36
- const content = contentStructure instanceof Function ? contentStructure({
37
- blocks
38
- }) : contentStructure;
35
+ const [blocks,, onChange] = useEntityBlockEditor('postType', templateType); // Replicates the logic found in getEditedPostContent().
36
+
37
+ let content;
38
+
39
+ if (contentStructure instanceof Function) {
40
+ content = contentStructure({
41
+ blocks
42
+ });
43
+ } else if (blocks) {
44
+ // If we have parsed blocks already, they should be our source of truth.
45
+ // Parsing applies block deprecations and legacy block conversions that
46
+ // unparsed content will not have.
47
+ content = __unstableSerializeAndClean(blocks);
48
+ } else {
49
+ content = contentStructure;
50
+ }
51
+
39
52
  const {
40
53
  switchEditorMode
41
54
  } = useDispatch(editSiteStore);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/code-editor/index.js"],"names":["parse","useEntityBlockEditor","useEntityProp","useSelect","useDispatch","store","keyboardShortcutsStore","__","Button","editSiteStore","CodeEditorTextArea","CodeEditor","templateType","shortcut","select","getEditedPostType","getShortcutRepresentation","contentStructure","setContent","blocks","onChange","content","Function","switchEditorMode","newContent","selection","undefined"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,KAAT,QAAsB,mBAAtB;AACA,SAASC,oBAAT,EAA+BC,aAA/B,QAAoD,sBAApD;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,KAAK,IAAIC,sBAAlB,QAAgD,+BAAhD;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,MAAT,QAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,SAASH,KAAK,IAAII,aAAlB,QAAuC,aAAvC;AACA,OAAOC,kBAAP,MAA+B,yBAA/B;AAEA,eAAe,SAASC,UAAT,GAAsB;AACpC,QAAM;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MAA6BV,SAAS,CAAIW,MAAF,IAAc;AAC3D,UAAM;AAAEC,MAAAA;AAAF,QAAwBD,MAAM,CAAEL,aAAF,CAApC;AACA,UAAM;AAAEO,MAAAA;AAAF,QAAgCF,MAAM,CAAER,sBAAF,CAA5C;AACA,WAAO;AACNM,MAAAA,YAAY,EAAEG,iBAAiB,EADzB;AAENF,MAAAA,QAAQ,EAAEG,yBAAyB,CAAE,4BAAF;AAF7B,KAAP;AAIA,GAP2C,EAOzC,EAPyC,CAA5C;AAQA,QAAM,CAAEC,gBAAF,EAAoBC,UAApB,IAAmChB,aAAa,CACrD,UADqD,EAErDU,YAFqD,EAGrD,SAHqD,CAAtD;AAKA,QAAM,CAAEO,MAAF,GAAYC,QAAZ,IAAyBnB,oBAAoB,CAClD,UADkD,EAElDW,YAFkD,CAAnD;AAIA,QAAMS,OAAO,GACZJ,gBAAgB,YAAYK,QAA5B,GACGL,gBAAgB,CAAE;AAAEE,IAAAA;AAAF,GAAF,CADnB,GAEGF,gBAHJ;AAIA,QAAM;AAAEM,IAAAA;AAAF,MAAuBnB,WAAW,CAAEK,aAAF,CAAxC;AACA,SACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,0BAAMF,EAAE,CAAE,cAAF,CAAR,CADD,EAEC,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,UADT;AAEC,IAAA,OAAO,EAAG,MAAMgB,gBAAgB,CAAE,QAAF,CAFjC;AAGC,IAAA,QAAQ,EAAGV;AAHZ,KAKGN,EAAE,CAAE,kBAAF,CALL,CAFD,CADD,EAWC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,cAAC,kBAAD;AACC,IAAA,KAAK,EAAGc,OADT;AAEC,IAAA,QAAQ,EAAKG,UAAF,IAAkB;AAC5BJ,MAAAA,QAAQ,CAAEpB,KAAK,CAAEwB,UAAF,CAAP,EAAuB;AAC9BC,QAAAA,SAAS,EAAEC;AADmB,OAAvB,CAAR;AAGA,KANF;AAOC,IAAA,OAAO,EAAGR;AAPX,IADD,CAXD,CADD;AAyBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { parse } from '@wordpress/blocks';\nimport { useEntityBlockEditor, useEntityProp } from '@wordpress/core-data';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\nimport { __ } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\nimport CodeEditorTextArea from './code-editor-text-area';\n\nexport default function CodeEditor() {\n\tconst { templateType, shortcut } = useSelect( ( select ) => {\n\t\tconst { getEditedPostType } = select( editSiteStore );\n\t\tconst { getShortcutRepresentation } = select( keyboardShortcutsStore );\n\t\treturn {\n\t\t\ttemplateType: getEditedPostType(),\n\t\t\tshortcut: getShortcutRepresentation( 'core/edit-site/toggle-mode' ),\n\t\t};\n\t}, [] );\n\tconst [ contentStructure, setContent ] = useEntityProp(\n\t\t'postType',\n\t\ttemplateType,\n\t\t'content'\n\t);\n\tconst [ blocks, , onChange ] = useEntityBlockEditor(\n\t\t'postType',\n\t\ttemplateType\n\t);\n\tconst content =\n\t\tcontentStructure instanceof Function\n\t\t\t? contentStructure( { blocks } )\n\t\t\t: contentStructure;\n\tconst { switchEditorMode } = useDispatch( editSiteStore );\n\treturn (\n\t\t<div className=\"edit-site-code-editor\">\n\t\t\t<div className=\"edit-site-code-editor__toolbar\">\n\t\t\t\t<h2>{ __( 'Editing code' ) }</h2>\n\t\t\t\t<Button\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\tonClick={ () => switchEditorMode( 'visual' ) }\n\t\t\t\t\tshortcut={ shortcut }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Exit code editor' ) }\n\t\t\t\t</Button>\n\t\t\t</div>\n\t\t\t<div className=\"edit-site-code-editor__body\">\n\t\t\t\t<CodeEditorTextArea\n\t\t\t\t\tvalue={ content }\n\t\t\t\t\tonChange={ ( newContent ) => {\n\t\t\t\t\t\tonChange( parse( newContent ), {\n\t\t\t\t\t\t\tselection: undefined,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tonInput={ setContent }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/code-editor/index.js"],"names":["parse","__unstableSerializeAndClean","useEntityBlockEditor","useEntityProp","useSelect","useDispatch","store","keyboardShortcutsStore","__","Button","editSiteStore","CodeEditorTextArea","CodeEditor","templateType","shortcut","select","getEditedPostType","getShortcutRepresentation","contentStructure","setContent","blocks","onChange","content","Function","switchEditorMode","newContent","selection","undefined"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,KAAT,EAAgBC,2BAAhB,QAAmD,mBAAnD;AACA,SAASC,oBAAT,EAA+BC,aAA/B,QAAoD,sBAApD;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,KAAK,IAAIC,sBAAlB,QAAgD,+BAAhD;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,MAAT,QAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,SAASH,KAAK,IAAII,aAAlB,QAAuC,aAAvC;AACA,OAAOC,kBAAP,MAA+B,yBAA/B;AAEA,eAAe,SAASC,UAAT,GAAsB;AACpC,QAAM;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MAA6BV,SAAS,CAAIW,MAAF,IAAc;AAC3D,UAAM;AAAEC,MAAAA;AAAF,QAAwBD,MAAM,CAAEL,aAAF,CAApC;AACA,UAAM;AAAEO,MAAAA;AAAF,QAAgCF,MAAM,CAAER,sBAAF,CAA5C;AACA,WAAO;AACNM,MAAAA,YAAY,EAAEG,iBAAiB,EADzB;AAENF,MAAAA,QAAQ,EAAEG,yBAAyB,CAAE,4BAAF;AAF7B,KAAP;AAIA,GAP2C,EAOzC,EAPyC,CAA5C;AAQA,QAAM,CAAEC,gBAAF,EAAoBC,UAApB,IAAmChB,aAAa,CACrD,UADqD,EAErDU,YAFqD,EAGrD,SAHqD,CAAtD;AAKA,QAAM,CAAEO,MAAF,GAAYC,QAAZ,IAAyBnB,oBAAoB,CAClD,UADkD,EAElDW,YAFkD,CAAnD,CAdoC,CAmBpC;;AACA,MAAIS,OAAJ;;AACA,MAAKJ,gBAAgB,YAAYK,QAAjC,EAA4C;AAC3CD,IAAAA,OAAO,GAAGJ,gBAAgB,CAAE;AAAEE,MAAAA;AAAF,KAAF,CAA1B;AACA,GAFD,MAEO,IAAKA,MAAL,EAAc;AACpB;AACA;AACA;AACAE,IAAAA,OAAO,GAAGrB,2BAA2B,CAAEmB,MAAF,CAArC;AACA,GALM,MAKA;AACNE,IAAAA,OAAO,GAAGJ,gBAAV;AACA;;AAED,QAAM;AAAEM,IAAAA;AAAF,MAAuBnB,WAAW,CAAEK,aAAF,CAAxC;AACA,SACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,0BAAMF,EAAE,CAAE,cAAF,CAAR,CADD,EAEC,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,UADT;AAEC,IAAA,OAAO,EAAG,MAAMgB,gBAAgB,CAAE,QAAF,CAFjC;AAGC,IAAA,QAAQ,EAAGV;AAHZ,KAKGN,EAAE,CAAE,kBAAF,CALL,CAFD,CADD,EAWC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,cAAC,kBAAD;AACC,IAAA,KAAK,EAAGc,OADT;AAEC,IAAA,QAAQ,EAAKG,UAAF,IAAkB;AAC5BJ,MAAAA,QAAQ,CAAErB,KAAK,CAAEyB,UAAF,CAAP,EAAuB;AAC9BC,QAAAA,SAAS,EAAEC;AADmB,OAAvB,CAAR;AAGA,KANF;AAOC,IAAA,OAAO,EAAGR;AAPX,IADD,CAXD,CADD;AAyBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\nimport { useEntityBlockEditor, useEntityProp } from '@wordpress/core-data';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\nimport { __ } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\nimport CodeEditorTextArea from './code-editor-text-area';\n\nexport default function CodeEditor() {\n\tconst { templateType, shortcut } = useSelect( ( select ) => {\n\t\tconst { getEditedPostType } = select( editSiteStore );\n\t\tconst { getShortcutRepresentation } = select( keyboardShortcutsStore );\n\t\treturn {\n\t\t\ttemplateType: getEditedPostType(),\n\t\t\tshortcut: getShortcutRepresentation( 'core/edit-site/toggle-mode' ),\n\t\t};\n\t}, [] );\n\tconst [ contentStructure, setContent ] = useEntityProp(\n\t\t'postType',\n\t\ttemplateType,\n\t\t'content'\n\t);\n\tconst [ blocks, , onChange ] = useEntityBlockEditor(\n\t\t'postType',\n\t\ttemplateType\n\t);\n\n\t// Replicates the logic found in getEditedPostContent().\n\tlet content;\n\tif ( contentStructure instanceof Function ) {\n\t\tcontent = contentStructure( { blocks } );\n\t} else if ( blocks ) {\n\t\t// If we have parsed blocks already, they should be our source of truth.\n\t\t// Parsing applies block deprecations and legacy block conversions that\n\t\t// unparsed content will not have.\n\t\tcontent = __unstableSerializeAndClean( blocks );\n\t} else {\n\t\tcontent = contentStructure;\n\t}\n\n\tconst { switchEditorMode } = useDispatch( editSiteStore );\n\treturn (\n\t\t<div className=\"edit-site-code-editor\">\n\t\t\t<div className=\"edit-site-code-editor__toolbar\">\n\t\t\t\t<h2>{ __( 'Editing code' ) }</h2>\n\t\t\t\t<Button\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\tonClick={ () => switchEditorMode( 'visual' ) }\n\t\t\t\t\tshortcut={ shortcut }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Exit code editor' ) }\n\t\t\t\t</Button>\n\t\t\t</div>\n\t\t\t<div className=\"edit-site-code-editor__body\">\n\t\t\t\t<CodeEditorTextArea\n\t\t\t\t\tvalue={ content }\n\t\t\t\t\tonChange={ ( newContent ) => {\n\t\t\t\t\t\tonChange( parse( newContent ), {\n\t\t\t\t\t\t\tselection: undefined,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tonInput={ setContent }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n"]}