@wordpress/edit-site 4.3.6 → 4.3.7
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.
- package/build/components/add-new-template/new-template.js +8 -1
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/template-details/index.js +4 -2
- package/build/components/template-details/index.js.map +1 -1
- package/build-module/components/add-new-template/new-template.js +7 -1
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/template-details/index.js +4 -2
- package/build-module/components/template-details/index.js.map +1 -1
- package/package.json +7 -7
- package/src/components/add-new-template/new-template.js +5 -0
- package/src/components/template-details/index.js +4 -1
|
@@ -25,6 +25,8 @@ var _notices = require("@wordpress/notices");
|
|
|
25
25
|
|
|
26
26
|
var _routes = require("../routes");
|
|
27
27
|
|
|
28
|
+
var _store = require("../../store");
|
|
29
|
+
|
|
28
30
|
/**
|
|
29
31
|
* External dependencies
|
|
30
32
|
*/
|
|
@@ -73,6 +75,9 @@ function NewTemplate(_ref) {
|
|
|
73
75
|
const {
|
|
74
76
|
createErrorNotice
|
|
75
77
|
} = (0, _data.useDispatch)(_notices.store);
|
|
78
|
+
const {
|
|
79
|
+
setTemplate
|
|
80
|
+
} = (0, _data.useDispatch)(_store.store);
|
|
76
81
|
|
|
77
82
|
async function createTemplate(_ref2) {
|
|
78
83
|
let {
|
|
@@ -94,7 +99,9 @@ function NewTemplate(_ref) {
|
|
|
94
99
|
title
|
|
95
100
|
}, {
|
|
96
101
|
throwOnError: true
|
|
97
|
-
}); //
|
|
102
|
+
}); // Set template before navigating away to avoid initial stale value.
|
|
103
|
+
|
|
104
|
+
setTemplate(template.id, template.slug); // Navigate to the created template editor.
|
|
98
105
|
|
|
99
106
|
history.push({
|
|
100
107
|
postId: template.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","home","post","page","archive","search","notFound","index","list","category","author","postAuthor","taxonomy","blockMeta","date","postDate","tag","attachment","media","NewTemplate","postType","history","templates","defaultTemplateTypes","select","coreStore","getEntityRecords","per_page","editorStore","__experimentalGetDefaultTemplateTypes","saveEntityRecord","createErrorNotice","noticesStore","createTemplate","slug","title","description","template","excerpt","toString","status","throwOnError","
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","home","post","page","archive","search","notFound","index","list","category","author","postAuthor","taxonomy","blockMeta","date","postDate","tag","attachment","media","NewTemplate","postType","history","templates","defaultTemplateTypes","select","coreStore","getEntityRecords","per_page","editorStore","__experimentalGetDefaultTemplateTypes","saveEntityRecord","createErrorNotice","noticesStore","setTemplate","editSiteStore","createTemplate","slug","title","description","template","excerpt","toString","status","throwOnError","id","push","postId","type","error","errorMessage","message","code","existingTemplateSlugs","missingTemplates","length","sort","template1","template2","indexOf","labels","add_new","add_new_item","noArrow","variant"],"mappings":";;;;;;;;;AAGA;;AAKA;;AAMA;;AACA;;AACA;;AACA;;AAeA;;AACA;;AAKA;;AACA;;AAvCA;AACA;AACA;;AAGA;AACA;AACA;;AA4BA;AACA;AACA;AAIA,MAAMA,sBAAsB,GAAG,CAC9B,YAD8B,EAE9B,aAF8B,EAG9B,MAH8B,EAI9B,OAJ8B,EAK9B,SAL8B,EAM9B,QAN8B,EAO9B,UAP8B,EAQ9B,MAR8B,EAS9B,KAT8B,EAU9B,UAV8B,EAW9B,QAX8B,EAY9B,KAZ8B,CAA/B;AAeA,MAAMC,cAAc,GAAG;AACtB,gBAAcC,WADQ;AAEtB,iBAAeC,WAFO;AAGtBC,EAAAA,IAAI,EAAJA,WAHsB;AAItBC,EAAAA,OAAO,EAAPA,cAJsB;AAKtBC,EAAAA,MAAM,EAANA,aALsB;AAMtB,OAAKC,eANiB;AAOtBC,EAAAA,KAAK,EAAEC,WAPe;AAQtBC,EAAA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AEC,IAAA,IAAI,EAAG,IAFR;AAGC,IAAA,IAAI,EAAGhB,QAAQ,CAACuC,MAAT,CAAgBC,OAHxB;AAIC,IAAA,KAAK,EAAGxC,QAAQ,CAACuC,MAAT,CAAgBE,YAJzB;AAKC,IAAA,YAAY,EAAG;AACdC,MAAAA,OAAO,EAAE;AADK,KALhB;AAQC,IAAA,WAAW,EAAG;AACbC,MAAAA,OAAO,EAAE;AADI;AARf,KAYG,MACD,4BAAC,yBAAD;AAAe,IAAA,SAAS,EAAC;AAAzB,KACC,4BAAC,qBAAD;AAAW,IAAA,KAAK,EAAG3C,QAAQ,CAACuC,MAAT,CAAgBE;AAAnC,KACG,iBACDR,gBADC,EAED;AAAA,QAAE;AAAEhB,MAAAA,KAAF;AAASC,MAAAA,WAAT;AAAsBF,MAAAA;AAAtB,KAAF;AAAA,WACC,4BAAC,oBAAD;AACC,MAAA,IAAI,EAAGpC,cAAc,CAAEoC,IAAF,CADtB;AAEC,MAAA,YAAY,EAAC,MAFd;AAGC,MAAA,IAAI,EAAGE,WAHR;AAIC,MAAA,GAAG,EAAGF,IAJP;AAKC,MAAA,OAAO,EAAG,MAAM;AACfD,QAAAA,cAAc,CAAE;AAAEC,UAAAA;AAAF,SAAF,CAAd,CADe,CAEf;AACA;AARF,OAUGC,KAVH,CADD;AAAA,GAFC,CADH,CADD,CAbF,CADD;AAsCA","sourcesContent":["/**\n * External dependencies\n */\nimport { filter, find, includes, map } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tNavigableMenu,\n} from '@wordpress/components';\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 { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { useHistory } from '../routes';\nimport { store as editSiteStore } from '../../store';\n\nconst DEFAULT_TEMPLATE_SLUGS = [\n\t'front-page',\n\t'single-post',\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\t'single-post': 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 { templates, defaultTemplateTypes } = useSelect(\n\t\t( select ) => ( {\n\t\t\ttemplates: 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: select(\n\t\t\t\teditorStore\n\t\t\t).__experimentalGetDefaultTemplateTypes(),\n\t\t} ),\n\t\t[]\n\t);\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst { setTemplate } = useDispatch( editSiteStore );\n\n\tasync function createTemplate( { slug } ) {\n\t\ttry {\n\t\t\tconst { title, description } = find( defaultTemplateTypes, {\n\t\t\t\tslug,\n\t\t\t} );\n\n\t\t\tconst template = 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\texcerpt: description,\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},\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( template.id, template.slug );\n\n\t\t\t// Navigate to the created template editor.\n\t\t\thistory.push( {\n\t\t\t\tpostId: template.id,\n\t\t\t\tpostType: template.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 existingTemplateSlugs = map( templates, 'slug' );\n\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\tif ( ! missingTemplates.length ) {\n\t\treturn null;\n\t}\n\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\n\treturn (\n\t\t<DropdownMenu\n\t\t\tclassName=\"edit-site-new-template-dropdown\"\n\t\t\ticon={ null }\n\t\t\ttext={ postType.labels.add_new }\n\t\t\tlabel={ postType.labels.add_new_item }\n\t\t\tpopoverProps={ {\n\t\t\t\tnoArrow: false,\n\t\t\t} }\n\t\t\ttoggleProps={ {\n\t\t\t\tvariant: 'primary',\n\t\t\t} }\n\t\t>\n\t\t\t{ () => (\n\t\t\t\t<NavigableMenu className=\"edit-site-new-template-dropdown__popover\">\n\t\t\t\t\t<MenuGroup label={ postType.labels.add_new_item }>\n\t\t\t\t\t\t{ map(\n\t\t\t\t\t\t\tmissingTemplates,\n\t\t\t\t\t\t\t( { title, description, slug } ) => (\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\ticon={ TEMPLATE_ICONS[ slug ] }\n\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\tinfo={ description }\n\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tcreateTemplate( { slug } );\n\t\t\t\t\t\t\t\t\t\t// We will be navigated way so no need to close the dropdown.\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ title }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t) }\n\t\t\t\t\t</MenuGroup>\n\t\t\t\t</NavigableMenu>\n\t\t\t) }\n\t\t</DropdownMenu>\n\t);\n}\n"]}
|
|
@@ -69,7 +69,9 @@ function TemplateDetails(_ref) {
|
|
|
69
69
|
// TODO: We should update this to filter by template part's areas as well.
|
|
70
70
|
postType: template.type,
|
|
71
71
|
postId: undefined
|
|
72
|
-
});
|
|
72
|
+
}); // Only user-created and non-default templates can change the name.
|
|
73
|
+
|
|
74
|
+
const canEditTitle = template.is_custom && !template.has_theme_file;
|
|
73
75
|
|
|
74
76
|
if (!template) {
|
|
75
77
|
return null;
|
|
@@ -84,7 +86,7 @@ function TemplateDetails(_ref) {
|
|
|
84
86
|
className: "edit-site-template-details"
|
|
85
87
|
}, (0, _element.createElement)("div", {
|
|
86
88
|
className: "edit-site-template-details__group"
|
|
87
|
-
},
|
|
89
|
+
}, canEditTitle ? (0, _element.createElement)(_editTemplateTitle.default, {
|
|
88
90
|
template: template
|
|
89
91
|
}) : (0, _element.createElement)(_components.__experimentalHeading, {
|
|
90
92
|
level: 4,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/template-details/index.js"],"names":["TemplateDetails","template","onClose","title","description","select","editorStore","__experimentalGetTemplateInfo","revertTemplate","editSiteStore","templateSubMenu","type","menu","MENU_TEMPLATES","TEMPLATE_PARTS_SUB_MENUS","find","area","browseAllLinkProps","postType","postId","undefined","
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/template-details/index.js"],"names":["TemplateDetails","template","onClose","title","description","select","editorStore","__experimentalGetTemplateInfo","revertTemplate","editSiteStore","templateSubMenu","type","menu","MENU_TEMPLATES","TEMPLATE_PARTS_SUB_MENUS","find","area","browseAllLinkProps","postType","postId","undefined","canEditTitle","is_custom","has_theme_file","revert"],"mappings":";;;;;;;;;AAGA;;;;AACA;;AACA;;AAOA;;AACA;;AAKA;;AACA;;AAIA;;AACA;;AACA;;AACA;;AA1BA;AACA;AACA;;AAaA;AACA;AACA;AAWe,SAASA,eAAT,OAAkD;AAAA,MAAxB;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,GAAwB;AAChE,QAAM;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,MAAyB,qBAC5BC,MAAF,IACCA,MAAM,CAAEC,aAAF,CAAN,CAAsBC,6BAAtB,CAAqDN,QAArD,CAF6B,EAG9B,EAH8B,CAA/B;AAKA,QAAM;AAAEO,IAAAA;AAAF,MAAqB,uBAAaC,YAAb,CAA3B;AAEA,QAAMC,eAAe,GAAG,sBAAS,MAAM;AACtC,QAAK,CAAAT,QAAQ,SAAR,IAAAA,QAAQ,WAAR,YAAAA,QAAQ,CAAEU,IAAV,MAAmB,aAAxB,EAAwC;AACvC,aAAO;AAAER,QAAAA,KAAK,EAAE,cAAI,WAAJ,CAAT;AAA4BS,QAAAA,IAAI,EAAEC;AAAlC,OAAP;AACA;;AAED,WAAOC,oCAAyBC,IAAzB,CACN;AAAA,UAAE;AAAEC,QAAAA;AAAF,OAAF;AAAA,aAAgBA,IAAI,MAAKf,QAAL,aAAKA,QAAL,uBAAKA,QAAQ,CAAEe,IAAf,CAApB;AAAA,KAD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AEMP,kBAFN,GAIG;AACD;AACA,gBAAI,eAAJ,CAFC,EAGDP,eAAe,CAACP,KAHf,CAJH,CAvCD,CADD;AAoDA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\nimport { sprintf, __ } from '@wordpress/i18n';\nimport {\n\tButton,\n\tMenuGroup,\n\tMenuItem,\n\t__experimentalHeading as Heading,\n\t__experimentalText as Text,\n} from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as editorStore } from '@wordpress/editor';\n\n/**\n * Internal dependencies\n */\nimport isTemplateRevertable from '../../utils/is-template-revertable';\nimport {\n\tMENU_TEMPLATES,\n\tTEMPLATE_PARTS_SUB_MENUS,\n} from '../navigation-sidebar/navigation-panel/constants';\nimport { store as editSiteStore } from '../../store';\nimport TemplateAreas from './template-areas';\nimport EditTemplateTitle from './edit-template-title';\nimport { useLink } from '../routes/link';\n\nexport default function TemplateDetails( { template, onClose } ) {\n\tconst { title, description } = useSelect(\n\t\t( select ) =>\n\t\t\tselect( editorStore ).__experimentalGetTemplateInfo( template ),\n\t\t[]\n\t);\n\tconst { revertTemplate } = useDispatch( editSiteStore );\n\n\tconst templateSubMenu = useMemo( () => {\n\t\tif ( template?.type === 'wp_template' ) {\n\t\t\treturn { title: __( 'templates' ), menu: MENU_TEMPLATES };\n\t\t}\n\n\t\treturn TEMPLATE_PARTS_SUB_MENUS.find(\n\t\t\t( { area } ) => area === template?.area\n\t\t);\n\t}, [ template ] );\n\n\tconst browseAllLinkProps = useLink( {\n\t\t// TODO: We should update this to filter by template part's areas as well.\n\t\tpostType: template.type,\n\t\tpostId: undefined,\n\t} );\n\n\t// Only user-created and non-default templates can change the name.\n\tconst canEditTitle = template.is_custom && ! template.has_theme_file;\n\n\tif ( ! template ) {\n\t\treturn null;\n\t}\n\n\tconst revert = () => {\n\t\trevertTemplate( template );\n\t\tonClose();\n\t};\n\n\treturn (\n\t\t<div className=\"edit-site-template-details\">\n\t\t\t<div className=\"edit-site-template-details__group\">\n\t\t\t\t{ canEditTitle ? (\n\t\t\t\t\t<EditTemplateTitle template={ template } />\n\t\t\t\t) : (\n\t\t\t\t\t<Heading\n\t\t\t\t\t\tlevel={ 4 }\n\t\t\t\t\t\tweight={ 600 }\n\t\t\t\t\t\tclassName=\"edit-site-template-details__title\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ title }\n\t\t\t\t\t</Heading>\n\t\t\t\t) }\n\n\t\t\t\t{ description && (\n\t\t\t\t\t<Text\n\t\t\t\t\t\tsize=\"body\"\n\t\t\t\t\t\tclassName=\"edit-site-template-details__description\"\n\t\t\t\t\t\tas=\"p\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ description }\n\t\t\t\t\t</Text>\n\t\t\t\t) }\n\t\t\t</div>\n\n\t\t\t<TemplateAreas closeTemplateDetailsDropdown={ onClose } />\n\n\t\t\t{ isTemplateRevertable( template ) && (\n\t\t\t\t<MenuGroup className=\"edit-site-template-details__group edit-site-template-details__revert\">\n\t\t\t\t\t<MenuItem\n\t\t\t\t\t\tclassName=\"edit-site-template-details__revert-button\"\n\t\t\t\t\t\tinfo={ __( 'Restore template to default state' ) }\n\t\t\t\t\t\tonClick={ revert }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Clear customizations' ) }\n\t\t\t\t\t</MenuItem>\n\t\t\t\t</MenuGroup>\n\t\t\t) }\n\n\t\t\t<Button\n\t\t\t\tclassName=\"edit-site-template-details__show-all-button\"\n\t\t\t\t{ ...browseAllLinkProps }\n\t\t\t>\n\t\t\t\t{ sprintf(\n\t\t\t\t\t/* translators: the template part's area name (\"Headers\", \"Sidebars\") or \"templates\". */\n\t\t\t\t\t__( 'Browse all %s' ),\n\t\t\t\t\ttemplateSubMenu.title\n\t\t\t\t) }\n\t\t\t</Button>\n\t\t</div>\n\t);\n}\n"]}
|
|
@@ -20,6 +20,7 @@ import { store as noticesStore } from '@wordpress/notices';
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
import { useHistory } from '../routes';
|
|
23
|
+
import { store as editSiteStore } from '../../store';
|
|
23
24
|
const DEFAULT_TEMPLATE_SLUGS = ['front-page', 'single-post', 'page', 'index', 'archive', 'author', 'category', 'date', 'tag', 'taxonomy', 'search', '404'];
|
|
24
25
|
const TEMPLATE_ICONS = {
|
|
25
26
|
'front-page': home,
|
|
@@ -56,6 +57,9 @@ export default function NewTemplate(_ref) {
|
|
|
56
57
|
const {
|
|
57
58
|
createErrorNotice
|
|
58
59
|
} = useDispatch(noticesStore);
|
|
60
|
+
const {
|
|
61
|
+
setTemplate
|
|
62
|
+
} = useDispatch(editSiteStore);
|
|
59
63
|
|
|
60
64
|
async function createTemplate(_ref2) {
|
|
61
65
|
let {
|
|
@@ -77,7 +81,9 @@ export default function NewTemplate(_ref) {
|
|
|
77
81
|
title
|
|
78
82
|
}, {
|
|
79
83
|
throwOnError: true
|
|
80
|
-
}); //
|
|
84
|
+
}); // Set template before navigating away to avoid initial stale value.
|
|
85
|
+
|
|
86
|
+
setTemplate(template.id, template.slug); // Navigate to the created template editor.
|
|
81
87
|
|
|
82
88
|
history.push({
|
|
83
89
|
postId: template.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["filter","find","includes","map","DropdownMenu","MenuGroup","MenuItem","NavigableMenu","useSelect","useDispatch","store","coreStore","editorStore","archive","blockMeta","category","home","list","media","notFound","page","post","postAuthor","postDate","search","tag","__","noticesStore","useHistory","DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","index","author","taxonomy","date","attachment","NewTemplate","postType","history","templates","defaultTemplateTypes","select","getEntityRecords","per_page","__experimentalGetDefaultTemplateTypes","saveEntityRecord","createErrorNotice","createTemplate","slug","title","description","template","excerpt","toString","status","throwOnError","
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["filter","find","includes","map","DropdownMenu","MenuGroup","MenuItem","NavigableMenu","useSelect","useDispatch","store","coreStore","editorStore","archive","blockMeta","category","home","list","media","notFound","page","post","postAuthor","postDate","search","tag","__","noticesStore","useHistory","editSiteStore","DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","index","author","taxonomy","date","attachment","NewTemplate","postType","history","templates","defaultTemplateTypes","select","getEntityRecords","per_page","__experimentalGetDefaultTemplateTypes","saveEntityRecord","createErrorNotice","setTemplate","createTemplate","slug","title","description","template","excerpt","toString","status","throwOnError","id","push","postId","type","error","errorMessage","message","code","existingTemplateSlugs","missingTemplates","length","sort","template1","template2","indexOf","labels","add_new","add_new_item","noArrow","variant"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,MAAT,EAAiBC,IAAjB,EAAuBC,QAAvB,EAAiCC,GAAjC,QAA4C,QAA5C;AAEA;AACA;AACA;;AACA,SACCC,YADD,EAECC,SAFD,EAGCC,QAHD,EAICC,aAJD,QAKO,uBALP;AAMA,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,QAAmB,iBAAnB;AACA,SAAShB,KAAK,IAAIiB,YAAlB,QAAsC,oBAAtC;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,WAA3B;AACA,SAASlB,KAAK,IAAImB,aAAlB,QAAuC,aAAvC;AAEA,MAAMC,sBAAsB,GAAG,CAC9B,YAD8B,EAE9B,aAF8B,EAG9B,MAH8B,EAI9B,OAJ8B,EAK9B,SAL8B,EAM9B,QAN8B,EAO9B,UAP8B,EAQ9B,MAR8B,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find, includes, map } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tNavigableMenu,\n} from '@wordpress/components';\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 { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { useHistory } from '../routes';\nimport { store as editSiteStore } from '../../store';\n\nconst DEFAULT_TEMPLATE_SLUGS = [\n\t'front-page',\n\t'single-post',\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\t'single-post': 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 { templates, defaultTemplateTypes } = useSelect(\n\t\t( select ) => ( {\n\t\t\ttemplates: 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: select(\n\t\t\t\teditorStore\n\t\t\t).__experimentalGetDefaultTemplateTypes(),\n\t\t} ),\n\t\t[]\n\t);\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst { setTemplate } = useDispatch( editSiteStore );\n\n\tasync function createTemplate( { slug } ) {\n\t\ttry {\n\t\t\tconst { title, description } = find( defaultTemplateTypes, {\n\t\t\t\tslug,\n\t\t\t} );\n\n\t\t\tconst template = 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\texcerpt: description,\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},\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( template.id, template.slug );\n\n\t\t\t// Navigate to the created template editor.\n\t\t\thistory.push( {\n\t\t\t\tpostId: template.id,\n\t\t\t\tpostType: template.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 existingTemplateSlugs = map( templates, 'slug' );\n\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\tif ( ! missingTemplates.length ) {\n\t\treturn null;\n\t}\n\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\n\treturn (\n\t\t<DropdownMenu\n\t\t\tclassName=\"edit-site-new-template-dropdown\"\n\t\t\ticon={ null }\n\t\t\ttext={ postType.labels.add_new }\n\t\t\tlabel={ postType.labels.add_new_item }\n\t\t\tpopoverProps={ {\n\t\t\t\tnoArrow: false,\n\t\t\t} }\n\t\t\ttoggleProps={ {\n\t\t\t\tvariant: 'primary',\n\t\t\t} }\n\t\t>\n\t\t\t{ () => (\n\t\t\t\t<NavigableMenu className=\"edit-site-new-template-dropdown__popover\">\n\t\t\t\t\t<MenuGroup label={ postType.labels.add_new_item }>\n\t\t\t\t\t\t{ map(\n\t\t\t\t\t\t\tmissingTemplates,\n\t\t\t\t\t\t\t( { title, description, slug } ) => (\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\ticon={ TEMPLATE_ICONS[ slug ] }\n\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\tinfo={ description }\n\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tcreateTemplate( { slug } );\n\t\t\t\t\t\t\t\t\t\t// We will be navigated way so no need to close the dropdown.\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ title }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t) }\n\t\t\t\t\t</MenuGroup>\n\t\t\t\t</NavigableMenu>\n\t\t\t) }\n\t\t</DropdownMenu>\n\t);\n}\n"]}
|
|
@@ -50,7 +50,9 @@ export default function TemplateDetails(_ref) {
|
|
|
50
50
|
// TODO: We should update this to filter by template part's areas as well.
|
|
51
51
|
postType: template.type,
|
|
52
52
|
postId: undefined
|
|
53
|
-
});
|
|
53
|
+
}); // Only user-created and non-default templates can change the name.
|
|
54
|
+
|
|
55
|
+
const canEditTitle = template.is_custom && !template.has_theme_file;
|
|
54
56
|
|
|
55
57
|
if (!template) {
|
|
56
58
|
return null;
|
|
@@ -65,7 +67,7 @@ export default function TemplateDetails(_ref) {
|
|
|
65
67
|
className: "edit-site-template-details"
|
|
66
68
|
}, createElement("div", {
|
|
67
69
|
className: "edit-site-template-details__group"
|
|
68
|
-
},
|
|
70
|
+
}, canEditTitle ? createElement(EditTemplateTitle, {
|
|
69
71
|
template: template
|
|
70
72
|
}) : createElement(Heading, {
|
|
71
73
|
level: 4,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/template-details/index.js"],"names":["useMemo","sprintf","__","Button","MenuGroup","MenuItem","__experimentalHeading","Heading","__experimentalText","Text","useDispatch","useSelect","store","editorStore","isTemplateRevertable","MENU_TEMPLATES","TEMPLATE_PARTS_SUB_MENUS","editSiteStore","TemplateAreas","EditTemplateTitle","useLink","TemplateDetails","template","onClose","title","description","select","__experimentalGetTemplateInfo","revertTemplate","templateSubMenu","type","menu","find","area","browseAllLinkProps","postType","postId","undefined","
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/template-details/index.js"],"names":["useMemo","sprintf","__","Button","MenuGroup","MenuItem","__experimentalHeading","Heading","__experimentalText","Text","useDispatch","useSelect","store","editorStore","isTemplateRevertable","MENU_TEMPLATES","TEMPLATE_PARTS_SUB_MENUS","editSiteStore","TemplateAreas","EditTemplateTitle","useLink","TemplateDetails","template","onClose","title","description","select","__experimentalGetTemplateInfo","revertTemplate","templateSubMenu","type","menu","find","area","browseAllLinkProps","postType","postId","undefined","canEditTitle","is_custom","has_theme_file","revert"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,OAAT,QAAwB,oBAAxB;AACA,SAASC,OAAT,EAAkBC,EAAlB,QAA4B,iBAA5B;AACA,SACCC,MADD,EAECC,SAFD,EAGCC,QAHD,EAICC,qBAAqB,IAAIC,OAJ1B,EAKCC,kBAAkB,IAAIC,IALvB,QAMO,uBANP;AAOA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,KAAK,IAAIC,WAAlB,QAAq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CAwBhE;;AACA,QAAMC,YAAY,GAAGhB,QAAQ,CAACiB,SAAT,IAAsB,CAAEjB,QAAQ,CAACkB,cAAtD;;AAEA,MAAK,CAAElB,QAAP,EAAkB;AACjB,WAAO,IAAP;AACA;;AAED,QAAMmB,MAAM,GAAG,MAAM;AACpBb,IAAAA,cAAc,CAAEN,QAAF,CAAd;AACAC,IAAAA,OAAO;AACP,GAHD;;AAKA,SACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACGe,YAAY,GACb,cAAC,iBAAD;AAAmB,IAAA,QAAQ,EAAGhB;AAA9B,IADa,GAGb,cAAC,OAAD;AACC,IAAA,KAAK,EAAG,CADT;AAEC,IAAA,MAAM,EAAG,GAFV;AAGC,IAAA,SAAS,EAAC;AAHX,KAKGE,KALH,CAJF,EAaGC,WAAW,IACZ,cAAC,IAAD;AACC,IAAA,IAAI,EAAC,MADN;AAEC,IAAA,SAAS,EAAC,yCAFX;AAGC,IAAA,EAAE,EAAC;AAHJ,KAKGA,WALH,CAdF,CADD,EAyBC,cAAC,aAAD;AAAe,IAAA,4BAA4B,EAAGF;AAA9C,IAzBD,EA2BGT,oBAAoB,CAAEQ,QAAF,CAApB,IACD,cAAC,SAAD;AAAW,IAAA,SAAS,EAAC;AAArB,KACC,cAAC,QAAD;AACC,IAAA,SAAS,EAAC,2CADX;AAEC,IAAA,IAAI,EAAGpB,EAAE,CAAE,mCAAF,CAFV;AAGC,IAAA,OAAO,EAAGuC;AAHX,KAKGvC,EAAE,CAAE,sBAAF,CALL,CADD,CA5BF,EAuCC,cAAC,MAAD;AACC,IAAA,SAAS,EAAC;AADX,KAEMgC,kBAFN,GAIGjC,OAAO;AACR;AACAC,EAAAA,EAAE,CAAE,eAAF,CAFM,EAGR2B,eAAe,CAACL,KAHR,CAJV,CAvCD,CADD;AAoDA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\nimport { sprintf, __ } from '@wordpress/i18n';\nimport {\n\tButton,\n\tMenuGroup,\n\tMenuItem,\n\t__experimentalHeading as Heading,\n\t__experimentalText as Text,\n} from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as editorStore } from '@wordpress/editor';\n\n/**\n * Internal dependencies\n */\nimport isTemplateRevertable from '../../utils/is-template-revertable';\nimport {\n\tMENU_TEMPLATES,\n\tTEMPLATE_PARTS_SUB_MENUS,\n} from '../navigation-sidebar/navigation-panel/constants';\nimport { store as editSiteStore } from '../../store';\nimport TemplateAreas from './template-areas';\nimport EditTemplateTitle from './edit-template-title';\nimport { useLink } from '../routes/link';\n\nexport default function TemplateDetails( { template, onClose } ) {\n\tconst { title, description } = useSelect(\n\t\t( select ) =>\n\t\t\tselect( editorStore ).__experimentalGetTemplateInfo( template ),\n\t\t[]\n\t);\n\tconst { revertTemplate } = useDispatch( editSiteStore );\n\n\tconst templateSubMenu = useMemo( () => {\n\t\tif ( template?.type === 'wp_template' ) {\n\t\t\treturn { title: __( 'templates' ), menu: MENU_TEMPLATES };\n\t\t}\n\n\t\treturn TEMPLATE_PARTS_SUB_MENUS.find(\n\t\t\t( { area } ) => area === template?.area\n\t\t);\n\t}, [ template ] );\n\n\tconst browseAllLinkProps = useLink( {\n\t\t// TODO: We should update this to filter by template part's areas as well.\n\t\tpostType: template.type,\n\t\tpostId: undefined,\n\t} );\n\n\t// Only user-created and non-default templates can change the name.\n\tconst canEditTitle = template.is_custom && ! template.has_theme_file;\n\n\tif ( ! template ) {\n\t\treturn null;\n\t}\n\n\tconst revert = () => {\n\t\trevertTemplate( template );\n\t\tonClose();\n\t};\n\n\treturn (\n\t\t<div className=\"edit-site-template-details\">\n\t\t\t<div className=\"edit-site-template-details__group\">\n\t\t\t\t{ canEditTitle ? (\n\t\t\t\t\t<EditTemplateTitle template={ template } />\n\t\t\t\t) : (\n\t\t\t\t\t<Heading\n\t\t\t\t\t\tlevel={ 4 }\n\t\t\t\t\t\tweight={ 600 }\n\t\t\t\t\t\tclassName=\"edit-site-template-details__title\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ title }\n\t\t\t\t\t</Heading>\n\t\t\t\t) }\n\n\t\t\t\t{ description && (\n\t\t\t\t\t<Text\n\t\t\t\t\t\tsize=\"body\"\n\t\t\t\t\t\tclassName=\"edit-site-template-details__description\"\n\t\t\t\t\t\tas=\"p\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ description }\n\t\t\t\t\t</Text>\n\t\t\t\t) }\n\t\t\t</div>\n\n\t\t\t<TemplateAreas closeTemplateDetailsDropdown={ onClose } />\n\n\t\t\t{ isTemplateRevertable( template ) && (\n\t\t\t\t<MenuGroup className=\"edit-site-template-details__group edit-site-template-details__revert\">\n\t\t\t\t\t<MenuItem\n\t\t\t\t\t\tclassName=\"edit-site-template-details__revert-button\"\n\t\t\t\t\t\tinfo={ __( 'Restore template to default state' ) }\n\t\t\t\t\t\tonClick={ revert }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Clear customizations' ) }\n\t\t\t\t\t</MenuItem>\n\t\t\t\t</MenuGroup>\n\t\t\t) }\n\n\t\t\t<Button\n\t\t\t\tclassName=\"edit-site-template-details__show-all-button\"\n\t\t\t\t{ ...browseAllLinkProps }\n\t\t\t>\n\t\t\t\t{ sprintf(\n\t\t\t\t\t/* translators: the template part's area name (\"Headers\", \"Sidebars\") or \"templates\". */\n\t\t\t\t\t__( 'Browse all %s' ),\n\t\t\t\t\ttemplateSubMenu.title\n\t\t\t\t) }\n\t\t\t</Button>\n\t\t</div>\n\t);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/edit-site",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.7",
|
|
4
4
|
"description": "Edit Site Page module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -29,28 +29,28 @@
|
|
|
29
29
|
"@babel/runtime": "^7.16.0",
|
|
30
30
|
"@wordpress/a11y": "^3.6.1",
|
|
31
31
|
"@wordpress/api-fetch": "^6.3.1",
|
|
32
|
-
"@wordpress/block-editor": "^8.5.
|
|
33
|
-
"@wordpress/block-library": "^7.3.
|
|
32
|
+
"@wordpress/block-editor": "^8.5.6",
|
|
33
|
+
"@wordpress/block-library": "^7.3.7",
|
|
34
34
|
"@wordpress/blocks": "^11.5.3",
|
|
35
35
|
"@wordpress/components": "^19.8.4",
|
|
36
36
|
"@wordpress/compose": "^5.4.1",
|
|
37
37
|
"@wordpress/core-data": "^4.4.5",
|
|
38
38
|
"@wordpress/data": "^6.6.1",
|
|
39
39
|
"@wordpress/deprecated": "^3.6.1",
|
|
40
|
-
"@wordpress/editor": "^12.5.
|
|
40
|
+
"@wordpress/editor": "^12.5.6",
|
|
41
41
|
"@wordpress/element": "^4.4.1",
|
|
42
42
|
"@wordpress/hooks": "^3.6.1",
|
|
43
43
|
"@wordpress/html-entities": "^3.6.1",
|
|
44
44
|
"@wordpress/i18n": "^4.6.1",
|
|
45
45
|
"@wordpress/icons": "^8.2.2",
|
|
46
|
-
"@wordpress/interface": "^4.5.
|
|
46
|
+
"@wordpress/interface": "^4.5.5",
|
|
47
47
|
"@wordpress/keyboard-shortcuts": "^3.4.1",
|
|
48
48
|
"@wordpress/keycodes": "^3.6.1",
|
|
49
49
|
"@wordpress/media-utils": "^3.4.1",
|
|
50
50
|
"@wordpress/notices": "^3.6.1",
|
|
51
51
|
"@wordpress/plugins": "^4.4.2",
|
|
52
52
|
"@wordpress/preferences": "^1.2.4",
|
|
53
|
-
"@wordpress/reusable-blocks": "^3.4.
|
|
53
|
+
"@wordpress/reusable-blocks": "^3.4.6",
|
|
54
54
|
"@wordpress/style-engine": "^0.5.1",
|
|
55
55
|
"@wordpress/url": "^3.7.1",
|
|
56
56
|
"@wordpress/viewport": "^4.4.1",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"publishConfig": {
|
|
69
69
|
"access": "public"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "89fbea298119228eea3ebdc8d30e87033a497f43"
|
|
72
72
|
}
|
|
@@ -37,6 +37,7 @@ import { store as noticesStore } from '@wordpress/notices';
|
|
|
37
37
|
* Internal dependencies
|
|
38
38
|
*/
|
|
39
39
|
import { useHistory } from '../routes';
|
|
40
|
+
import { store as editSiteStore } from '../../store';
|
|
40
41
|
|
|
41
42
|
const DEFAULT_TEMPLATE_SLUGS = [
|
|
42
43
|
'front-page',
|
|
@@ -86,6 +87,7 @@ export default function NewTemplate( { postType } ) {
|
|
|
86
87
|
);
|
|
87
88
|
const { saveEntityRecord } = useDispatch( coreStore );
|
|
88
89
|
const { createErrorNotice } = useDispatch( noticesStore );
|
|
90
|
+
const { setTemplate } = useDispatch( editSiteStore );
|
|
89
91
|
|
|
90
92
|
async function createTemplate( { slug } ) {
|
|
91
93
|
try {
|
|
@@ -106,6 +108,9 @@ export default function NewTemplate( { postType } ) {
|
|
|
106
108
|
{ throwOnError: true }
|
|
107
109
|
);
|
|
108
110
|
|
|
111
|
+
// Set template before navigating away to avoid initial stale value.
|
|
112
|
+
setTemplate( template.id, template.slug );
|
|
113
|
+
|
|
109
114
|
// Navigate to the created template editor.
|
|
110
115
|
history.push( {
|
|
111
116
|
postId: template.id,
|
|
@@ -50,6 +50,9 @@ export default function TemplateDetails( { template, onClose } ) {
|
|
|
50
50
|
postId: undefined,
|
|
51
51
|
} );
|
|
52
52
|
|
|
53
|
+
// Only user-created and non-default templates can change the name.
|
|
54
|
+
const canEditTitle = template.is_custom && ! template.has_theme_file;
|
|
55
|
+
|
|
53
56
|
if ( ! template ) {
|
|
54
57
|
return null;
|
|
55
58
|
}
|
|
@@ -62,7 +65,7 @@ export default function TemplateDetails( { template, onClose } ) {
|
|
|
62
65
|
return (
|
|
63
66
|
<div className="edit-site-template-details">
|
|
64
67
|
<div className="edit-site-template-details__group">
|
|
65
|
-
{
|
|
68
|
+
{ canEditTitle ? (
|
|
66
69
|
<EditTemplateTitle template={ template } />
|
|
67
70
|
) : (
|
|
68
71
|
<Heading
|