@wordpress/edit-site 4.12.1-next.d6164808d3.0 → 4.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/build/components/add-new-template/new-template.js +1 -1
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/add-new-template/utils.js +90 -52
- package/build/components/add-new-template/utils.js.map +1 -1
- package/build/components/block-editor/index.js +20 -10
- package/build/components/block-editor/index.js.map +1 -1
- package/build/components/block-editor/resizable-editor.js +8 -1
- package/build/components/block-editor/resizable-editor.js.map +1 -1
- package/build/components/editor/index.js +9 -4
- package/build/components/editor/index.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +40 -23
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/gradients-palette-panel.js +6 -2
- package/build/components/global-styles/gradients-palette-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js +5 -3
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/preview.js +2 -2
- package/build/components/global-styles/preview.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +41 -29
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +1 -1
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/header/index.js +41 -5
- package/build/components/header/index.js.map +1 -1
- package/build/components/list/header.js +15 -2
- package/build/components/list/header.js.map +1 -1
- package/build/components/navigation-sidebar/navigation-panel/index.js +10 -4
- package/build/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
- package/build/components/sidebar/index.js +8 -3
- package/build/components/sidebar/index.js.map +1 -1
- package/build/components/template-part-converter/convert-to-template-part.js +16 -0
- package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
- package/build/index.js +4 -1
- package/build/index.js.map +1 -1
- package/build-module/components/add-new-template/new-template.js +2 -2
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +87 -52
- package/build-module/components/add-new-template/utils.js.map +1 -1
- package/build-module/components/block-editor/index.js +20 -9
- package/build-module/components/block-editor/index.js.map +1 -1
- package/build-module/components/block-editor/resizable-editor.js +9 -2
- package/build-module/components/block-editor/resizable-editor.js.map +1 -1
- package/build-module/components/editor/index.js +10 -5
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +40 -23
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/gradients-palette-panel.js +6 -2
- package/build-module/components/global-styles/gradients-palette-panel.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +6 -4
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/preview.js +2 -2
- package/build-module/components/global-styles/preview.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +42 -30
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +1 -1
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/header/index.js +42 -7
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/list/header.js +14 -2
- package/build-module/components/list/header.js.map +1 -1
- package/build-module/components/navigation-sidebar/navigation-panel/index.js +11 -5
- package/build-module/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
- package/build-module/components/sidebar/index.js +7 -3
- package/build-module/components/sidebar/index.js.map +1 -1
- package/build-module/components/template-part-converter/convert-to-template-part.js +16 -1
- package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
- package/build-module/index.js +4 -1
- package/build-module/index.js.map +1 -1
- package/build-style/style-rtl.css +28 -16
- package/build-style/style.css +28 -16
- package/package.json +29 -29
- package/src/components/add-new-template/new-template.js +2 -0
- package/src/components/add-new-template/utils.js +82 -20
- package/src/components/block-editor/index.js +34 -16
- package/src/components/block-editor/resizable-editor.js +10 -3
- package/src/components/code-editor/style.scss +2 -3
- package/src/components/editor/index.js +12 -5
- package/src/components/global-styles/dimensions-panel.js +52 -31
- package/src/components/global-styles/gradients-palette-panel.js +25 -12
- package/src/components/global-styles/hooks.js +7 -7
- package/src/components/global-styles/preview.js +2 -2
- package/src/components/global-styles/use-global-styles-output.js +66 -57
- package/src/components/global-styles/utils.js +1 -1
- package/src/components/header/index.js +61 -21
- package/src/components/header/style.scss +9 -0
- package/src/components/list/header.js +15 -5
- package/src/components/navigation-sidebar/navigation-panel/index.js +30 -24
- package/src/components/sidebar/index.js +23 -20
- package/src/components/template-part-converter/convert-to-template-part.js +14 -1
- package/src/index.js +4 -0
- package/src/style.scss +1 -0
|
@@ -63,6 +63,7 @@ const NavigationPanel = _ref2 => {
|
|
|
63
63
|
const {
|
|
64
64
|
homeTemplate,
|
|
65
65
|
isNavigationOpen,
|
|
66
|
+
isTemplatePartsMode,
|
|
66
67
|
siteTitle
|
|
67
68
|
} = (0, _data.useSelect)(select => {
|
|
68
69
|
const {
|
|
@@ -73,10 +74,15 @@ const NavigationPanel = _ref2 => {
|
|
|
73
74
|
isNavigationOpened
|
|
74
75
|
} = select(_store.store);
|
|
75
76
|
const siteData = getEntityRecord('root', '__unstableBase', undefined) || {};
|
|
77
|
+
const {
|
|
78
|
+
supportsTemplatePartsMode,
|
|
79
|
+
__unstableHomeTemplate
|
|
80
|
+
} = getSettings();
|
|
76
81
|
return {
|
|
77
82
|
siteTitle: siteData.name,
|
|
78
|
-
homeTemplate:
|
|
79
|
-
isNavigationOpen: isNavigationOpened()
|
|
83
|
+
homeTemplate: __unstableHomeTemplate,
|
|
84
|
+
isNavigationOpen: isNavigationOpened(),
|
|
85
|
+
isTemplatePartsMode: !!supportsTemplatePartsMode
|
|
80
86
|
};
|
|
81
87
|
}, []);
|
|
82
88
|
const {
|
|
@@ -112,7 +118,7 @@ const NavigationPanel = _ref2 => {
|
|
|
112
118
|
href: "index.php"
|
|
113
119
|
})), (0, _element.createElement)(_components.__experimentalNavigationMenu, null, (0, _element.createElement)(_components.__experimentalNavigationGroup, {
|
|
114
120
|
title: (0, _i18n.__)('Editor')
|
|
115
|
-
}, (0, _element.createElement)(NavLink, {
|
|
121
|
+
}, !isTemplatePartsMode && (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(NavLink, {
|
|
116
122
|
icon: _icons.home,
|
|
117
123
|
title: (0, _i18n.__)('Site'),
|
|
118
124
|
item: SITE_EDITOR_KEY,
|
|
@@ -128,7 +134,7 @@ const NavigationPanel = _ref2 => {
|
|
|
128
134
|
postId: undefined,
|
|
129
135
|
postType: 'wp_template'
|
|
130
136
|
}
|
|
131
|
-
}), (0, _element.createElement)(NavLink, {
|
|
137
|
+
})), (0, _element.createElement)(NavLink, {
|
|
132
138
|
icon: _icons.symbolFilled,
|
|
133
139
|
title: (0, _i18n.__)('Template Parts'),
|
|
134
140
|
item: "wp_template_part",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/navigation-sidebar/navigation-panel/index.js"],"names":["SITE_EDITOR_KEY","NavLink","params","replace","props","linkProps","NavigationPanel","activeItem","homeTemplate","isNavigationOpen","siteTitle","select","getEntityRecord","coreDataStore","getSettings","isNavigationOpened","editSiteStore","siteData","undefined","
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/navigation-sidebar/navigation-panel/index.js"],"names":["SITE_EDITOR_KEY","NavLink","params","replace","props","linkProps","NavigationPanel","activeItem","homeTemplate","isNavigationOpen","isTemplatePartsMode","siteTitle","select","getEntityRecord","coreDataStore","getSettings","isNavigationOpened","editSiteStore","siteData","undefined","supportsTemplatePartsMode","__unstableHomeTemplate","name","setIsNavigationPanelOpened","closeOnEscape","event","keyCode","ESCAPE","defaultPrevented","preventDefault","siteIcon","postId","postType","templateIcon","templatePartIcon"],"mappings":";;;;;;;;;;;;;AAGA;;AAKA;;AAOA;;AACA;;AACA;;AACA;;AACA;;AACA;;AASA;;AACA;;AACA;;AA/BA;AACA;AACA;;AAGA;AACA;AACA;;AAmBA;AACA;AACA;AAKA,MAAMA,eAAe,G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BC,4BAAC,OAAD;AACC,MAAA,IAAI,EAAGE,mBADR;AAEC,MAAA,KAAK,EAAG,cAAI,gBAAJ,CAFT;AAGC,MAAA,IAAI,EAAC,kBAHN;AAIC,MAAA,MAAM,EAAG;AACRH,QAAAA,MAAM,EAAEZ,SADA;AAERa,QAAAA,QAAQ,EAAE;AAFF;AAJV,MAxBD,CADD,CATD,CADD,CAND,CAND;AAFD;AAiEA,CA5FD;;eA8Fe1B,e","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalNavigation as Navigation,\n\t__experimentalNavigationBackButton as NavigationBackButton,\n\t__experimentalNavigationGroup as NavigationGroup,\n\t__experimentalNavigationItem as NavigationItem,\n\t__experimentalNavigationMenu as NavigationMenu,\n} from '@wordpress/components';\nimport { store as coreDataStore } from '@wordpress/core-data';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { ESCAPE } from '@wordpress/keycodes';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport {\n\thome as siteIcon,\n\tlayout as templateIcon,\n\tsymbolFilled as templatePartIcon,\n} from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { useLink } from '../../routes/link';\nimport MainDashboardButton from '../../main-dashboard-button';\nimport { store as editSiteStore } from '../../../store';\n\nconst SITE_EDITOR_KEY = 'site-editor';\n\nfunction NavLink( { params, replace, ...props } ) {\n\tconst linkProps = useLink( params, replace );\n\n\treturn <NavigationItem { ...linkProps } { ...props } />;\n}\n\nconst NavigationPanel = ( { activeItem = SITE_EDITOR_KEY } ) => {\n\tconst { homeTemplate, isNavigationOpen, isTemplatePartsMode, siteTitle } =\n\t\tuseSelect( ( select ) => {\n\t\t\tconst { getEntityRecord } = select( coreDataStore );\n\t\t\tconst { getSettings, isNavigationOpened } = select( editSiteStore );\n\n\t\t\tconst siteData =\n\t\t\t\tgetEntityRecord( 'root', '__unstableBase', undefined ) || {};\n\t\t\tconst { supportsTemplatePartsMode, __unstableHomeTemplate } =\n\t\t\t\tgetSettings();\n\n\t\t\treturn {\n\t\t\t\tsiteTitle: siteData.name,\n\t\t\t\thomeTemplate: __unstableHomeTemplate,\n\t\t\t\tisNavigationOpen: isNavigationOpened(),\n\t\t\t\tisTemplatePartsMode: !! supportsTemplatePartsMode,\n\t\t\t};\n\t\t}, [] );\n\tconst { setIsNavigationPanelOpened } = useDispatch( editSiteStore );\n\n\tconst closeOnEscape = ( event ) => {\n\t\tif ( event.keyCode === ESCAPE && ! event.defaultPrevented ) {\n\t\t\tevent.preventDefault();\n\t\t\tsetIsNavigationPanelOpened( false );\n\t\t}\n\t};\n\n\treturn (\n\t\t// eslint-disable-next-line jsx-a11y/no-static-element-interactions\n\t\t<div\n\t\t\tclassName={ classnames( `edit-site-navigation-panel`, {\n\t\t\t\t'is-open': isNavigationOpen,\n\t\t\t} ) }\n\t\t\tonKeyDown={ closeOnEscape }\n\t\t>\n\t\t\t<div className=\"edit-site-navigation-panel__inner\">\n\t\t\t\t<div className=\"edit-site-navigation-panel__site-title-container\">\n\t\t\t\t\t<div className=\"edit-site-navigation-panel__site-title\">\n\t\t\t\t\t\t{ decodeEntities( siteTitle ) }\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<div className=\"edit-site-navigation-panel__scroll-container\">\n\t\t\t\t\t<Navigation activeItem={ activeItem }>\n\t\t\t\t\t\t<MainDashboardButton.Slot>\n\t\t\t\t\t\t\t<NavigationBackButton\n\t\t\t\t\t\t\t\tbackButtonLabel={ __( 'Dashboard' ) }\n\t\t\t\t\t\t\t\tclassName=\"edit-site-navigation-panel__back-to-dashboard\"\n\t\t\t\t\t\t\t\thref=\"index.php\"\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</MainDashboardButton.Slot>\n\n\t\t\t\t\t\t<NavigationMenu>\n\t\t\t\t\t\t\t<NavigationGroup title={ __( 'Editor' ) }>\n\t\t\t\t\t\t\t\t{ ! isTemplatePartsMode && (\n\t\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t\t<NavLink\n\t\t\t\t\t\t\t\t\t\t\ticon={ siteIcon }\n\t\t\t\t\t\t\t\t\t\t\ttitle={ __( 'Site' ) }\n\t\t\t\t\t\t\t\t\t\t\titem={ SITE_EDITOR_KEY }\n\t\t\t\t\t\t\t\t\t\t\tparams={ {\n\t\t\t\t\t\t\t\t\t\t\t\tpostId: homeTemplate?.postId,\n\t\t\t\t\t\t\t\t\t\t\t\tpostType:\n\t\t\t\t\t\t\t\t\t\t\t\t\thomeTemplate?.postType,\n\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t<NavLink\n\t\t\t\t\t\t\t\t\t\t\ticon={ templateIcon }\n\t\t\t\t\t\t\t\t\t\t\ttitle={ __( 'Templates' ) }\n\t\t\t\t\t\t\t\t\t\t\titem=\"wp_template\"\n\t\t\t\t\t\t\t\t\t\t\tparams={ {\n\t\t\t\t\t\t\t\t\t\t\t\tpostId: undefined,\n\t\t\t\t\t\t\t\t\t\t\t\tpostType: 'wp_template',\n\t\t\t\t\t\t\t\t\t\t\t} }\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) }\n\t\t\t\t\t\t\t\t<NavLink\n\t\t\t\t\t\t\t\t\ticon={ templatePartIcon }\n\t\t\t\t\t\t\t\t\ttitle={ __( 'Template Parts' ) }\n\t\t\t\t\t\t\t\t\titem=\"wp_template_part\"\n\t\t\t\t\t\t\t\t\tparams={ {\n\t\t\t\t\t\t\t\t\t\tpostId: undefined,\n\t\t\t\t\t\t\t\t\t\tpostType: 'wp_template_part',\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</NavigationGroup>\n\t\t\t\t\t\t</NavigationMenu>\n\t\t\t\t\t</Navigation>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t);\n};\n\nexport default NavigationPanel;\n"]}
|
|
@@ -36,6 +36,8 @@ var _templateCard = _interopRequireDefault(require("./template-card"));
|
|
|
36
36
|
|
|
37
37
|
var _constants2 = require("./constants");
|
|
38
38
|
|
|
39
|
+
var _store = require("../../store");
|
|
40
|
+
|
|
39
41
|
/**
|
|
40
42
|
* WordPress dependencies
|
|
41
43
|
*/
|
|
@@ -54,16 +56,19 @@ function SidebarComplementaryAreaFills() {
|
|
|
54
56
|
const {
|
|
55
57
|
sidebar,
|
|
56
58
|
isEditorSidebarOpened,
|
|
57
|
-
hasBlockSelection
|
|
59
|
+
hasBlockSelection,
|
|
60
|
+
supportsGlobalStyles
|
|
58
61
|
} = (0, _data.useSelect)(select => {
|
|
59
62
|
const _sidebar = select(_interface.store).getActiveComplementaryArea(_constants.STORE_NAME);
|
|
60
63
|
|
|
61
64
|
const _isEditorSidebarOpened = [_constants2.SIDEBAR_BLOCK, _constants2.SIDEBAR_TEMPLATE].includes(_sidebar);
|
|
62
65
|
|
|
66
|
+
const settings = select(_store.store).getSettings();
|
|
63
67
|
return {
|
|
64
68
|
sidebar: _sidebar,
|
|
65
69
|
isEditorSidebarOpened: _isEditorSidebarOpened,
|
|
66
|
-
hasBlockSelection: !!select(_blockEditor.store).getBlockSelectionStart()
|
|
70
|
+
hasBlockSelection: !!select(_blockEditor.store).getBlockSelectionStart(),
|
|
71
|
+
supportsGlobalStyles: !(settings !== null && settings !== void 0 && settings.supportsTemplatePartsMode)
|
|
67
72
|
};
|
|
68
73
|
}, []);
|
|
69
74
|
const {
|
|
@@ -104,6 +109,6 @@ function SidebarComplementaryAreaFills() {
|
|
|
104
109
|
headerClassName: "edit-site-sidebar__panel-tabs"
|
|
105
110
|
}, sidebarName === _constants2.SIDEBAR_TEMPLATE && (0, _element.createElement)(_components.PanelBody, null, (0, _element.createElement)(_templateCard.default, null)), sidebarName === _constants2.SIDEBAR_BLOCK && (0, _element.createElement)(InspectorSlot, {
|
|
106
111
|
bubblesVirtually: true
|
|
107
|
-
})), (0, _element.createElement)(_globalStylesSidebar.default, null), (0, _element.createElement)(MaybeNavigationMenuSidebar, null));
|
|
112
|
+
})), supportsGlobalStyles && (0, _element.createElement)(_globalStylesSidebar.default, null), (0, _element.createElement)(MaybeNavigationMenuSidebar, null));
|
|
108
113
|
}
|
|
109
114
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/sidebar/index.js"],"names":["Slot","InspectorSlot","Fill","InspectorFill","SidebarInspectorFill","SidebarComplementaryAreaFills","sidebar","isEditorSidebarOpened","hasBlockSelection","select","_sidebar","interfaceStore","getActiveComplementaryArea","STORE_NAME","_isEditorSidebarOpened","SIDEBAR_BLOCK","SIDEBAR_TEMPLATE","includes","blockEditorStore","getBlockSelectionStart","enableComplementaryArea","sidebarName","MaybeNavigationMenuSidebar","Fragment","process","env","IS_GUTENBERG_PLUGIN","NavigationMenuSidebar","cog"],"mappings":";;;;;;;;;;AAMA;;AAHA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/sidebar/index.js"],"names":["Slot","InspectorSlot","Fill","InspectorFill","SidebarInspectorFill","SidebarComplementaryAreaFills","sidebar","isEditorSidebarOpened","hasBlockSelection","supportsGlobalStyles","select","_sidebar","interfaceStore","getActiveComplementaryArea","STORE_NAME","_isEditorSidebarOpened","SIDEBAR_BLOCK","SIDEBAR_TEMPLATE","includes","settings","editSiteStore","getSettings","blockEditorStore","getBlockSelectionStart","supportsTemplatePartsMode","enableComplementaryArea","sidebarName","MaybeNavigationMenuSidebar","Fragment","process","env","IS_GUTENBERG_PLUGIN","NavigationMenuSidebar","cog"],"mappings":";;;;;;;;;;AAMA;;AAHA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AAKA;;AACA;;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,CAAET,iBAAF,EAAqBD,qBAArB,CAPH;AASA,MAAImB,WAAW,GAAGpB,OAAlB;;AACA,MAAK,CAAEC,qBAAP,EAA+B;AAC9BmB,IAAAA,WAAW,GAAGlB,iBAAiB,GAAGQ,yBAAH,GAAmBC,4BAAlD;AACA,GApC8C,CAsC/C;AACA;AACA;;;AACA,MAAIU,0BAA0B,GAAGC,iBAAjC;;AAEA,MAAKC,OAAO,CAACC,GAAR,CAAYC,mBAAjB,EAAuC;AACtCJ,IAAAA,0BAA0B,GAAGK,8BAA7B;AACA;;AAED,SACC,qDACC,4BAAC,uBAAD;AACC,IAAA,UAAU,EAAGN,WADd;AAEC,IAAA,KAAK,EAAG,cAAI,UAAJ,CAFT;AAGC,IAAA,IAAI,EAAGO,UAHR;AAIC,IAAA,UAAU,EAAG,cAAI,wBAAJ,CAJd;AAKC,IAAA,MAAM,EAAG,4BAAC,uBAAD;AAAgB,MAAA,WAAW,EAAGP;AAA9B,MALV;AAMC,IAAA,eAAe,EAAC;AANjB,KAQGA,WAAW,KAAKT,4BAAhB,IACD,4BAAC,qBAAD,QACC,4BAAC,qBAAD,OADD,CATF,EAaGS,WAAW,KAAKV,yBAAhB,IACD,4BAAC,aAAD;AAAe,IAAA,gBAAgB;AAA/B,IAdF,CADD,EAkBGP,oBAAoB,IAAI,4BAAC,4BAAD,OAlB3B,EAmBC,4BAAC,0BAAD,OAnBD,CADD;AAuBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createSlotFill, PanelBody } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { cog } from '@wordpress/icons';\nimport { useEffect, Fragment } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as interfaceStore } from '@wordpress/interface';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport DefaultSidebar from './default-sidebar';\nimport GlobalStylesSidebar from './global-styles-sidebar';\nimport NavigationMenuSidebar from './navigation-menu-sidebar';\nimport { STORE_NAME } from '../../store/constants';\nimport SettingsHeader from './settings-header';\nimport TemplateCard from './template-card';\nimport { SIDEBAR_BLOCK, SIDEBAR_TEMPLATE } from './constants';\nimport { store as editSiteStore } from '../../store';\n\nconst { Slot: InspectorSlot, Fill: InspectorFill } = createSlotFill(\n\t'EditSiteSidebarInspector'\n);\nexport const SidebarInspectorFill = InspectorFill;\n\nexport function SidebarComplementaryAreaFills() {\n\tconst {\n\t\tsidebar,\n\t\tisEditorSidebarOpened,\n\t\thasBlockSelection,\n\t\tsupportsGlobalStyles,\n\t} = useSelect( ( select ) => {\n\t\tconst _sidebar =\n\t\t\tselect( interfaceStore ).getActiveComplementaryArea( STORE_NAME );\n\t\tconst _isEditorSidebarOpened = [\n\t\t\tSIDEBAR_BLOCK,\n\t\t\tSIDEBAR_TEMPLATE,\n\t\t].includes( _sidebar );\n\t\tconst settings = select( editSiteStore ).getSettings();\n\t\treturn {\n\t\t\tsidebar: _sidebar,\n\t\t\tisEditorSidebarOpened: _isEditorSidebarOpened,\n\t\t\thasBlockSelection:\n\t\t\t\t!! select( blockEditorStore ).getBlockSelectionStart(),\n\t\t\tsupportsGlobalStyles: ! settings?.supportsTemplatePartsMode,\n\t\t};\n\t}, [] );\n\tconst { enableComplementaryArea } = useDispatch( interfaceStore );\n\n\tuseEffect( () => {\n\t\tif ( ! isEditorSidebarOpened ) return;\n\t\tif ( hasBlockSelection ) {\n\t\t\tenableComplementaryArea( STORE_NAME, SIDEBAR_BLOCK );\n\t\t} else {\n\t\t\tenableComplementaryArea( STORE_NAME, SIDEBAR_TEMPLATE );\n\t\t}\n\t}, [ hasBlockSelection, isEditorSidebarOpened ] );\n\n\tlet sidebarName = sidebar;\n\tif ( ! isEditorSidebarOpened ) {\n\t\tsidebarName = hasBlockSelection ? SIDEBAR_BLOCK : SIDEBAR_TEMPLATE;\n\t}\n\n\t// Conditionally include NavMenu sidebar in Plugin only.\n\t// Optimise for dead code elimination.\n\t// See https://github.com/WordPress/gutenberg/blob/trunk/docs/how-to-guides/feature-flags.md#dead-code-elimination.\n\tlet MaybeNavigationMenuSidebar = Fragment;\n\n\tif ( process.env.IS_GUTENBERG_PLUGIN ) {\n\t\tMaybeNavigationMenuSidebar = NavigationMenuSidebar;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<DefaultSidebar\n\t\t\t\tidentifier={ sidebarName }\n\t\t\t\ttitle={ __( 'Settings' ) }\n\t\t\t\ticon={ cog }\n\t\t\t\tcloseLabel={ __( 'Close settings sidebar' ) }\n\t\t\t\theader={ <SettingsHeader sidebarName={ sidebarName } /> }\n\t\t\t\theaderClassName=\"edit-site-sidebar__panel-tabs\"\n\t\t\t>\n\t\t\t\t{ sidebarName === SIDEBAR_TEMPLATE && (\n\t\t\t\t\t<PanelBody>\n\t\t\t\t\t\t<TemplateCard />\n\t\t\t\t\t</PanelBody>\n\t\t\t\t) }\n\t\t\t\t{ sidebarName === SIDEBAR_BLOCK && (\n\t\t\t\t\t<InspectorSlot bubblesVirtually />\n\t\t\t\t) }\n\t\t\t</DefaultSidebar>\n\t\t\t{ supportsGlobalStyles && <GlobalStylesSidebar /> }\n\t\t\t<MaybeNavigationMenuSidebar />\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -29,6 +29,8 @@ var _icons = require("@wordpress/icons");
|
|
|
29
29
|
|
|
30
30
|
var _createTemplatePartModal = _interopRequireDefault(require("../create-template-part-modal"));
|
|
31
31
|
|
|
32
|
+
var _store = require("../../store");
|
|
33
|
+
|
|
32
34
|
/**
|
|
33
35
|
* External dependencies
|
|
34
36
|
*/
|
|
@@ -55,6 +57,20 @@ function ConvertToTemplatePart(_ref) {
|
|
|
55
57
|
const {
|
|
56
58
|
createSuccessNotice
|
|
57
59
|
} = (0, _data.useDispatch)(_notices.store);
|
|
60
|
+
const {
|
|
61
|
+
canCreate
|
|
62
|
+
} = (0, _data.useSelect)(select => {
|
|
63
|
+
const {
|
|
64
|
+
supportsTemplatePartsMode
|
|
65
|
+
} = select(_store.store).getSettings();
|
|
66
|
+
return {
|
|
67
|
+
canCreate: !supportsTemplatePartsMode
|
|
68
|
+
};
|
|
69
|
+
}, []);
|
|
70
|
+
|
|
71
|
+
if (!canCreate) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
58
74
|
|
|
59
75
|
const onConvert = async _ref2 => {
|
|
60
76
|
let {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/template-part-converter/convert-to-template-part.js"],"names":["ConvertToTemplatePart","clientIds","blocks","isModalOpen","setIsModalOpen","replaceBlocks","blockEditorStore","saveEntityRecord","coreStore","createSuccessNotice","noticesStore","onConvert","title","area","cleanSlug","replace","templatePart","slug","content","theme","type","symbolFilled"],"mappings":";;;;;;;;;AAgBA;;AAbA;;AAKA;;AACA;;AAIA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AAKA;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/template-part-converter/convert-to-template-part.js"],"names":["ConvertToTemplatePart","clientIds","blocks","isModalOpen","setIsModalOpen","replaceBlocks","blockEditorStore","saveEntityRecord","coreStore","createSuccessNotice","noticesStore","canCreate","select","supportsTemplatePartsMode","editSiteStore","getSettings","onConvert","title","area","cleanSlug","replace","templatePart","slug","content","theme","type","symbolFilled"],"mappings":";;;;;;;;;AAgBA;;AAbA;;AAKA;;AACA;;AAIA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AAKA;;AACA;;AAzBA;AACA;AACA;;AAGA;AACA;AACA;;AAcA;AACA;AACA;AAIe,SAASA,qBAAT,OAAwD;AAAA,MAAxB;AAAEC,IAAAA,SAAF;AAAaC,IAAAA;AAAb,GAAwB;AACtE,QAAM,CAAEC,WAAF,EAAeC,cAAf,IAAkC,uBAAU,KAAV,CAAxC;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAoB,uBAAaC,kBAAb,CAA1B;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAuB,uBAAaC,eAAb,CAA7B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A;AAJF,KAMG,cAAI,sBAAJ,CANH,CAFF,CADD,EAaGD,WAAW,IACZ,4BAAC,gCAAD;AACC,IAAA,UAAU,EAAG,MAAM;AAClBC,MAAAA,cAAc,CAAE,KAAF,CAAd;AACA,KAHF;AAIC,IAAA,QAAQ,EAAGY;AAJZ,IAdF,CADD;AAwBA","sourcesContent":["/**\n * External dependencies\n */\nimport { kebabCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport {\n\tBlockSettingsMenuControls,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { MenuItem } from '@wordpress/components';\nimport { createBlock, serialize } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { symbolFilled } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport CreateTemplatePartModal from '../create-template-part-modal';\nimport { store as editSiteStore } from '../../store';\n\nexport default function ConvertToTemplatePart( { clientIds, blocks } ) {\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst { replaceBlocks } = useDispatch( blockEditorStore );\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\tconst { canCreate } = useSelect( ( select ) => {\n\t\tconst { supportsTemplatePartsMode } =\n\t\t\tselect( editSiteStore ).getSettings();\n\t\treturn {\n\t\t\tcanCreate: ! supportsTemplatePartsMode,\n\t\t};\n\t}, [] );\n\n\tif ( ! canCreate ) {\n\t\treturn null;\n\t}\n\n\tconst onConvert = async ( { title, area } ) => {\n\t\t// Currently template parts only allow latin chars.\n\t\t// Fallback slug will receive suffix by default.\n\t\tconst cleanSlug =\n\t\t\tkebabCase( title ).replace( /[^\\w-]+/g, '' ) || 'wp-custom-part';\n\n\t\tconst templatePart = await saveEntityRecord(\n\t\t\t'postType',\n\t\t\t'wp_template_part',\n\t\t\t{\n\t\t\t\tslug: cleanSlug,\n\t\t\t\ttitle,\n\t\t\t\tcontent: serialize( blocks ),\n\t\t\t\tarea,\n\t\t\t}\n\t\t);\n\t\treplaceBlocks(\n\t\t\tclientIds,\n\t\t\tcreateBlock( 'core/template-part', {\n\t\t\t\tslug: templatePart.slug,\n\t\t\t\ttheme: templatePart.theme,\n\t\t\t} )\n\t\t);\n\t\tcreateSuccessNotice( __( 'Template part created.' ), {\n\t\t\ttype: 'snackbar',\n\t\t} );\n\n\t\t// The modal and this component will be unmounted because of `replaceBlocks` above,\n\t\t// so no need to call `closeModal` or `onClose`.\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<BlockSettingsMenuControls>\n\t\t\t\t{ () => (\n\t\t\t\t\t<MenuItem\n\t\t\t\t\t\ticon={ symbolFilled }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tsetIsModalOpen( true );\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Create Template part' ) }\n\t\t\t\t\t</MenuItem>\n\t\t\t\t) }\n\t\t\t</BlockSettingsMenuControls>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<CreateTemplatePartModal\n\t\t\t\t\tcloseModal={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\tonCreate={ onConvert }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
|
package/build/index.js
CHANGED
|
@@ -143,7 +143,10 @@ function reinitializeEditor(target, settings) {
|
|
|
143
143
|
// screen and land in the list screen.
|
|
144
144
|
(0, _data.dispatch)(_store.store).setIsNavigationPanelOpened((0, _data.select)(_viewport.store).isViewportMatch('medium'));
|
|
145
145
|
}
|
|
146
|
-
}
|
|
146
|
+
} // Prevent the default browser action for files dropped outside of dropzones.
|
|
147
|
+
|
|
148
|
+
window.addEventListener('dragover', e => e.preventDefault(), false);
|
|
149
|
+
window.addEventListener('drop', e => e.preventDefault(), false);
|
|
147
150
|
(0, _element.render)((0, _element.createElement)(_app.default, {
|
|
148
151
|
reboot: reboot
|
|
149
152
|
}), target);
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/index.js"],"names":["reinitializeEditor","target","settings","__unstableHomeTemplate","reboot","bind","preferencesStore","setDefaults","editorMode","fixedToolbar","focusMode","keepCaretInsideBlock","welcomeGuide","welcomeGuideStyles","showListViewByDefault","get","editSiteStore","setIsListViewOpened","interfaceStore","setDefaultComplementaryArea","updateSettings","editorStore","updateEditorSettings","defaultTemplateTypes","defaultTemplatePartAreas","isLandingOnListPage","window","location","href","setIsNavigationPanelOpened","viewportStore","isViewportMatch","initializeEditor","id","__experimentalFetchLinkSuggestions","search","searchOptions","__experimentalFetchRichUrlData","fetchUrlData","document","getElementById","blocksStore","__experimentalReapplyBlockTypeFilters","process","env","IS_GUTENBERG_PLUGIN","enableFSEBlocks"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA;;AANA;;AACA;;AAIA;;AAEA;;AAIA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/index.js"],"names":["reinitializeEditor","target","settings","__unstableHomeTemplate","reboot","bind","preferencesStore","setDefaults","editorMode","fixedToolbar","focusMode","keepCaretInsideBlock","welcomeGuide","welcomeGuideStyles","showListViewByDefault","get","editSiteStore","setIsListViewOpened","interfaceStore","setDefaultComplementaryArea","updateSettings","editorStore","updateEditorSettings","defaultTemplateTypes","defaultTemplatePartAreas","isLandingOnListPage","window","location","href","setIsNavigationPanelOpened","viewportStore","isViewportMatch","addEventListener","e","preventDefault","initializeEditor","id","__experimentalFetchLinkSuggestions","search","searchOptions","__experimentalFetchRichUrlData","fetchUrlData","document","getElementById","blocksStore","__experimentalReapplyBlockTypeFilters","process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C,oEAA8C;AAC7CC,MAAAA,eAAe,EAAE;AAD4B,KAA9C;AAGA;;AAEDjD,EAAAA,kBAAkB,CAAEC,MAAF,EAAUC,QAAV,CAAlB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as blocksStore } from '@wordpress/blocks';\nimport {\n\tregisterCoreBlocks,\n\t__experimentalRegisterExperimentalCoreBlocks,\n} from '@wordpress/block-library';\nimport { dispatch, select } from '@wordpress/data';\nimport { render, unmountComponentAtNode } from '@wordpress/element';\nimport {\n\t__experimentalFetchLinkSuggestions as fetchLinkSuggestions,\n\t__experimentalFetchUrlData as fetchUrlData,\n} from '@wordpress/core-data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { store as interfaceStore } from '@wordpress/interface';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport { __ } from '@wordpress/i18n';\nimport { store as viewportStore } from '@wordpress/viewport';\nimport { getQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport './hooks';\nimport { store as editSiteStore } from './store';\nimport EditSiteApp from './components/app';\nimport getIsListPage from './utils/get-is-list-page';\nimport ErrorBoundaryWarning from './components/error-boundary/warning';\n\n/**\n * Reinitializes the editor after the user chooses to reboot the editor after\n * an unhandled error occurs, replacing previously mounted editor element using\n * an initial state from prior to the crash.\n *\n * @param {Element} target DOM node in which editor is rendered.\n * @param {?Object} settings Editor settings object.\n */\nexport function reinitializeEditor( target, settings ) {\n\t// Display warning if editor wasn't able to resolve homepage template.\n\tif ( ! settings.__unstableHomeTemplate ) {\n\t\trender(\n\t\t\t<ErrorBoundaryWarning\n\t\t\t\tmessage={ __(\n\t\t\t\t\t'The editor is unable to find a block template for the homepage.'\n\t\t\t\t) }\n\t\t\t\tdashboardLink=\"index.php\"\n\t\t\t/>,\n\t\t\ttarget\n\t\t);\n\t\treturn;\n\t}\n\n\t// This will be a no-op if the target doesn't have any React nodes.\n\tunmountComponentAtNode( target );\n\tconst reboot = reinitializeEditor.bind( null, target, settings );\n\n\t// We dispatch actions and update the store synchronously before rendering\n\t// so that we won't trigger unnecessary re-renders with useEffect.\n\t{\n\t\tdispatch( preferencesStore ).setDefaults( 'core/edit-site', {\n\t\t\teditorMode: 'visual',\n\t\t\tfixedToolbar: false,\n\t\t\tfocusMode: false,\n\t\t\tkeepCaretInsideBlock: false,\n\t\t\twelcomeGuide: true,\n\t\t\twelcomeGuideStyles: true,\n\t\t\tshowListViewByDefault: false,\n\t\t} );\n\n\t\t// Check if the block list view should be open by default.\n\t\tif (\n\t\t\tselect( preferencesStore ).get(\n\t\t\t\t'core/edit-site',\n\t\t\t\t'showListViewByDefault'\n\t\t\t)\n\t\t) {\n\t\t\tdispatch( editSiteStore ).setIsListViewOpened( true );\n\t\t}\n\n\t\tdispatch( interfaceStore ).setDefaultComplementaryArea(\n\t\t\t'core/edit-site',\n\t\t\t'edit-site/template'\n\t\t);\n\n\t\tdispatch( editSiteStore ).updateSettings( settings );\n\n\t\t// Keep the defaultTemplateTypes in the core/editor settings too,\n\t\t// so that they can be selected with core/editor selectors in any editor.\n\t\t// This is needed because edit-site doesn't initialize with EditorProvider,\n\t\t// which internally uses updateEditorSettings as well.\n\t\tdispatch( editorStore ).updateEditorSettings( {\n\t\t\tdefaultTemplateTypes: settings.defaultTemplateTypes,\n\t\t\tdefaultTemplatePartAreas: settings.defaultTemplatePartAreas,\n\t\t} );\n\n\t\tconst isLandingOnListPage = getIsListPage(\n\t\t\tgetQueryArgs( window.location.href )\n\t\t);\n\n\t\tif ( isLandingOnListPage ) {\n\t\t\t// Default the navigation panel to be opened when we're in a bigger\n\t\t\t// screen and land in the list screen.\n\t\t\tdispatch( editSiteStore ).setIsNavigationPanelOpened(\n\t\t\t\tselect( viewportStore ).isViewportMatch( 'medium' )\n\t\t\t);\n\t\t}\n\t}\n\n\t// Prevent the default browser action for files dropped outside of dropzones.\n\twindow.addEventListener( 'dragover', ( e ) => e.preventDefault(), false );\n\twindow.addEventListener( 'drop', ( e ) => e.preventDefault(), false );\n\n\trender( <EditSiteApp reboot={ reboot } />, target );\n}\n\n/**\n * Initializes the site editor screen.\n *\n * @param {string} id ID of the root element to render the screen in.\n * @param {Object} settings Editor settings.\n */\nexport function initializeEditor( id, settings ) {\n\tsettings.__experimentalFetchLinkSuggestions = ( search, searchOptions ) =>\n\t\tfetchLinkSuggestions( search, searchOptions, settings );\n\tsettings.__experimentalFetchRichUrlData = fetchUrlData;\n\n\tconst target = document.getElementById( id );\n\n\tdispatch( blocksStore ).__experimentalReapplyBlockTypeFilters();\n\tregisterCoreBlocks();\n\tif ( process.env.IS_GUTENBERG_PLUGIN ) {\n\t\t__experimentalRegisterExperimentalCoreBlocks( {\n\t\t\tenableFSEBlocks: true,\n\t\t} );\n\t}\n\n\treinitializeEditor( target, settings );\n}\n\nexport { default as __experimentalMainDashboardButton } from './components/main-dashboard-button';\nexport { default as __experimentalNavigationToggle } from './components/navigation-sidebar/navigation-toggle';\nexport { default as PluginSidebar } from './components/sidebar/plugin-sidebar';\nexport { default as PluginSidebarMoreMenuItem } from './components/header/plugin-sidebar-more-menu-item';\nexport { default as PluginMoreMenuItem } from './components/header/plugin-more-menu-item';\n"]}
|
|
@@ -17,7 +17,7 @@ import { store as noticesStore } from '@wordpress/notices';
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import AddCustomTemplateModal from './add-custom-template-modal';
|
|
20
|
-
import { useExistingTemplates, useDefaultTemplateTypes, useTaxonomiesMenuItems, usePostTypeMenuItems, useAuthorMenuItem } from './utils';
|
|
20
|
+
import { useExistingTemplates, useDefaultTemplateTypes, useTaxonomiesMenuItems, usePostTypeMenuItems, useAuthorMenuItem, usePostTypeArchiveMenuItems } from './utils';
|
|
21
21
|
import AddCustomGenericTemplateModal from './add-custom-generic-template-modal';
|
|
22
22
|
import { useHistory } from '../routes';
|
|
23
23
|
import { store as editSiteStore } from '../../store';
|
|
@@ -213,7 +213,7 @@ function useMissingTemplates(setEntityForSuggestions, setShowCustomTemplateModal
|
|
|
213
213
|
enhancedMissingDefaultTemplateTypes === null || enhancedMissingDefaultTemplateTypes === void 0 ? void 0 : enhancedMissingDefaultTemplateTypes.sort((template1, template2) => {
|
|
214
214
|
return DEFAULT_TEMPLATE_SLUGS.indexOf(template1.slug) - DEFAULT_TEMPLATE_SLUGS.indexOf(template2.slug);
|
|
215
215
|
});
|
|
216
|
-
const missingTemplates = [...enhancedMissingDefaultTemplateTypes, ...postTypesMenuItems, ...taxonomiesMenuItems];
|
|
216
|
+
const missingTemplates = [...enhancedMissingDefaultTemplateTypes, ...usePostTypeArchiveMenuItems(), ...postTypesMenuItems, ...taxonomiesMenuItems];
|
|
217
217
|
return missingTemplates;
|
|
218
218
|
}
|
|
219
219
|
//# sourceMappingURL=new-template.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["apiFetch","addQueryArgs","DropdownMenu","MenuGroup","MenuItem","NavigableMenu","useState","useDispatch","store","coreStore","archive","blockMeta","category","home","list","media","notFound","page","post","postAuthor","postDate","search","tag","layout","customGenericTemplateIcon","__","sprintf","noticesStore","AddCustomTemplateModal","useExistingTemplates","useDefaultTemplateTypes","useTaxonomiesMenuItems","usePostTypeMenuItems","useAuthorMenuItem","AddCustomGenericTemplateModal","useHistory","editSiteStore","DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","single","index","author","taxonomy","date","attachment","NewTemplate","postType","showCustomTemplateModal","setShowCustomTemplateModal","showCustomGenericTemplateModal","setShowCustomGenericTemplateModal","entityForSuggestions","setEntityForSuggestions","history","saveEntityRecord","createErrorNotice","createSuccessNotice","setTemplate","createTemplate","template","isWPSuggestion","title","description","slug","templatePrefix","templateContent","content","fallbackTemplate","path","is_custom","template_prefix","newTemplate","toString","status","is_wp_suggestion","throwOnError","id","push","postId","type","error","errorMessage","message","code","missingTemplates","useMissingTemplates","length","labels","add_new","add_new_item","noArrow","variant","map","onClick","icon","existingTemplates","defaultTemplateTypes","existingTemplateSlugs","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","enhancedMissingDefaultTemplateTypes","defaultTaxonomiesMenuItems","taxonomiesMenuItems","defaultPostTypesMenuItems","postTypesMenuItems","authorMenuItem","forEach","menuItem","matchIndex","findIndex","sort","template1","template2","indexOf"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,SACCC,YADD,EAECC,SAFD,EAGCC,QAHD,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,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASlB,KAAK,IAAImB,YAAlB,QAAsC,oBAAtC;AAEA;AACA;AACA;;AACA,OAAOC,sBAAP,MAAmC,6BAAnC;AACA,SACCC,oBADD,EAECC,uBAFD,EAGCC,sBAHD,EAICC,oBAJD,EAKCC,iBALD,QAMO,SANP;AAOA,OAAOC,6BAAP,MAA0C,qCAA1C;AACA,SAASC,UAAT,QAA2B,WAA3B;AACA,SAAS3B,KAAK,IAAI4B,aAAlB,QAAuC,aAAvC;AAEA,MAAMC,sBAAsB,GAAG,CAC9B,YAD8B,EAE9B,QAF8B,EAG9B,MAH8B,EAI9B,OAJ8B,EAK9B,SAL8B,EAM9B,QAN8B,EAO9B,UAP8B,EAQ9B,MAR8B,EAS9B,KAT8B,EAU9B,UAV8B,EAW9B,QAX8B,EAY9B,KAZ8B,CAA/B;AAeA,MA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GxB,GAAGF,mBAHqB,CAAzB;AAKA,SAAOrB,gBAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tNavigableMenu,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tarchive,\n\tblockMeta,\n\tcategory,\n\thome,\n\tlist,\n\tmedia,\n\tnotFound,\n\tpage,\n\tpost,\n\tpostAuthor,\n\tpostDate,\n\tsearch,\n\ttag,\n\tlayout as customGenericTemplateIcon,\n} from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport AddCustomTemplateModal from './add-custom-template-modal';\nimport {\n\tuseExistingTemplates,\n\tuseDefaultTemplateTypes,\n\tuseTaxonomiesMenuItems,\n\tusePostTypeMenuItems,\n\tuseAuthorMenuItem,\n} from './utils';\nimport AddCustomGenericTemplateModal from './add-custom-generic-template-modal';\nimport { useHistory } from '../routes';\nimport { store as editSiteStore } from '../../store';\n\nconst DEFAULT_TEMPLATE_SLUGS = [\n\t'front-page',\n\t'single',\n\t'page',\n\t'index',\n\t'archive',\n\t'author',\n\t'category',\n\t'date',\n\t'tag',\n\t'taxonomy',\n\t'search',\n\t'404',\n];\n\nconst TEMPLATE_ICONS = {\n\t'front-page': home,\n\tsingle: post,\n\tpage,\n\tarchive,\n\tsearch,\n\t404: notFound,\n\tindex: list,\n\tcategory,\n\tauthor: postAuthor,\n\ttaxonomy: blockMeta,\n\tdate: postDate,\n\ttag,\n\tattachment: media,\n};\n\nexport default function NewTemplate( { postType } ) {\n\tconst [ showCustomTemplateModal, setShowCustomTemplateModal ] =\n\t\tuseState( false );\n\tconst [\n\t\tshowCustomGenericTemplateModal,\n\t\tsetShowCustomGenericTemplateModal,\n\t] = useState( false );\n\tconst [ entityForSuggestions, setEntityForSuggestions ] = useState( {} );\n\n\tconst history = useHistory();\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst { setTemplate } = useDispatch( editSiteStore );\n\n\tasync function createTemplate( template, isWPSuggestion = true ) {\n\t\ttry {\n\t\t\tconst { title, description, slug, templatePrefix } = template;\n\t\t\tlet templateContent = template.content;\n\t\t\t// Try to find fallback content from existing templates.\n\t\t\tif ( ! templateContent ) {\n\t\t\t\tconst fallbackTemplate = await apiFetch( {\n\t\t\t\t\tpath: addQueryArgs( '/wp/v2/templates/lookup', {\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tis_custom: ! isWPSuggestion,\n\t\t\t\t\t\ttemplate_prefix: templatePrefix,\n\t\t\t\t\t} ),\n\t\t\t\t} );\n\t\t\t\ttemplateContent = fallbackTemplate.content;\n\t\t\t}\n\t\t\tconst newTemplate = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tdescription,\n\t\t\t\t\t// Slugs need to be strings, so this is for template `404`\n\t\t\t\t\tslug: slug.toString(),\n\t\t\t\t\tstatus: 'publish',\n\t\t\t\t\ttitle,\n\t\t\t\t\tcontent: templateContent,\n\t\t\t\t\t// This adds a post meta field in template that is part of `is_custom` value calculation.\n\t\t\t\t\tis_wp_suggestion: isWPSuggestion,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\t// Set template before navigating away to avoid initial stale value.\n\t\t\tsetTemplate( newTemplate.id, newTemplate.slug );\n\n\t\t\t// Navigate to the created template editor.\n\t\t\thistory.push( {\n\t\t\t\tpostId: newTemplate.id,\n\t\t\t\tpostType: newTemplate.type,\n\t\t\t} );\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: Title of the created template e.g: \"Category\".\n\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\ttitle\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while creating the template.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t}\n\n\tconst missingTemplates = useMissingTemplates(\n\t\tsetEntityForSuggestions,\n\t\tsetShowCustomTemplateModal\n\t);\n\tif ( ! missingTemplates.length ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<>\n\t\t\t<DropdownMenu\n\t\t\t\tclassName=\"edit-site-new-template-dropdown\"\n\t\t\t\ticon={ null }\n\t\t\t\ttext={ postType.labels.add_new }\n\t\t\t\tlabel={ postType.labels.add_new_item }\n\t\t\t\tpopoverProps={ {\n\t\t\t\t\tnoArrow: false,\n\t\t\t\t} }\n\t\t\t\ttoggleProps={ {\n\t\t\t\t\tvariant: 'primary',\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ () => (\n\t\t\t\t\t<NavigableMenu className=\"edit-site-new-template-dropdown__popover\">\n\t\t\t\t\t\t<MenuGroup label={ postType.labels.add_new_item }>\n\t\t\t\t\t\t\t{ missingTemplates.map( ( template ) => {\n\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t\t\tonClick,\n\t\t\t\t\t\t\t\t\ticon,\n\t\t\t\t\t\t\t\t} = template;\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\t\t\ticon ||\n\t\t\t\t\t\t\t\t\t\t\tTEMPLATE_ICONS[ slug ] ||\n\t\t\t\t\t\t\t\t\t\t\tpost\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\t\tinfo={ description }\n\t\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t\tonClick\n\t\t\t\t\t\t\t\t\t\t\t\t? onClick( template )\n\t\t\t\t\t\t\t\t\t\t\t\t: createTemplate( template )\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ title }\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\ticon={ customGenericTemplateIcon }\n\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\tinfo={ __(\n\t\t\t\t\t\t\t\t\t'Custom templates can be applied to any post or page.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tkey=\"custom-template\"\n\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\tsetShowCustomGenericTemplateModal( true )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Custom template' ) }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t</NavigableMenu>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t\t{ showCustomTemplateModal && (\n\t\t\t\t<AddCustomTemplateModal\n\t\t\t\t\tonClose={ () => setShowCustomTemplateModal( false ) }\n\t\t\t\t\tonSelect={ createTemplate }\n\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showCustomGenericTemplateModal && (\n\t\t\t\t<AddCustomGenericTemplateModal\n\t\t\t\t\tonClose={ () => setShowCustomGenericTemplateModal( false ) }\n\t\t\t\t\tcreateTemplate={ createTemplate }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction useMissingTemplates(\n\tsetEntityForSuggestions,\n\tsetShowCustomTemplateModal\n) {\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst missingDefaultTemplates = ( defaultTemplateTypes || [] ).filter(\n\t\t( template ) =>\n\t\t\tDEFAULT_TEMPLATE_SLUGS.includes( template.slug ) &&\n\t\t\t! existingTemplateSlugs.includes( template.slug )\n\t);\n\tconst onClickMenuItem = ( _entityForSuggestions ) => {\n\t\tsetShowCustomTemplateModal( true );\n\t\tsetEntityForSuggestions( _entityForSuggestions );\n\t};\n\t// We need to replace existing default template types with\n\t// the create specific template functionality. The original\n\t// info (title, description, etc.) is preserved in the\n\t// used hooks.\n\tconst enhancedMissingDefaultTemplateTypes = [ ...missingDefaultTemplates ];\n\tconst { defaultTaxonomiesMenuItems, taxonomiesMenuItems } =\n\t\tuseTaxonomiesMenuItems( onClickMenuItem );\n\tconst { defaultPostTypesMenuItems, postTypesMenuItems } =\n\t\tusePostTypeMenuItems( onClickMenuItem );\n\n\tconst authorMenuItem = useAuthorMenuItem( onClickMenuItem );\n\t[\n\t\t...defaultTaxonomiesMenuItems,\n\t\t...defaultPostTypesMenuItems,\n\t\tauthorMenuItem,\n\t].forEach( ( menuItem ) => {\n\t\tif ( ! menuItem ) {\n\t\t\treturn;\n\t\t}\n\t\tconst matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(\n\t\t\t( template ) => template.slug === menuItem.slug\n\t\t);\n\t\t// Some default template types might have been filtered above from\n\t\t// `missingDefaultTemplates` because they only check for the general\n\t\t// template. So here we either replace or append the item, augmented\n\t\t// with the check if it has available specific item to create a\n\t\t// template for.\n\t\tif ( matchIndex > -1 ) {\n\t\t\tenhancedMissingDefaultTemplateTypes[ matchIndex ] = menuItem;\n\t\t} else {\n\t\t\tenhancedMissingDefaultTemplateTypes.push( menuItem );\n\t\t}\n\t} );\n\t// Update the sort order to match the DEFAULT_TEMPLATE_SLUGS order.\n\tenhancedMissingDefaultTemplateTypes?.sort( ( template1, template2 ) => {\n\t\treturn (\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template1.slug ) -\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template2.slug )\n\t\t);\n\t} );\n\tconst missingTemplates = [\n\t\t...enhancedMissingDefaultTemplateTypes,\n\t\t...postTypesMenuItems,\n\t\t...taxonomiesMenuItems,\n\t];\n\treturn missingTemplates;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["apiFetch","addQueryArgs","DropdownMenu","MenuGroup","MenuItem","NavigableMenu","useState","useDispatch","store","coreStore","archive","blockMeta","category","home","list","media","notFound","page","post","postAuthor","postDate","search","tag","layout","customGenericTemplateIcon","__","sprintf","noticesStore","AddCustomTemplateModal","useExistingTemplates","useDefaultTemplateTypes","useTaxonomiesMenuItems","usePostTypeMenuItems","useAuthorMenuItem","usePostTypeArchiveMenuItems","AddCustomGenericTemplateModal","useHistory","editSiteStore","DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","single","index","author","taxonomy","date","attachment","NewTemplate","postType","showCustomTemplateModal","setShowCustomTemplateModal","showCustomGenericTemplateModal","setShowCustomGenericTemplateModal","entityForSuggestions","setEntityForSuggestions","history","saveEntityRecord","createErrorNotice","createSuccessNotice","setTemplate","createTemplate","template","isWPSuggestion","title","description","slug","templatePrefix","templateContent","content","fallbackTemplate","path","is_custom","template_prefix","newTemplate","toString","status","is_wp_suggestion","throwOnError","id","push","postId","type","error","errorMessage","message","code","missingTemplates","useMissingTemplates","length","labels","add_new","add_new_item","noArrow","variant","map","onClick","icon","existingTemplates","defaultTemplateTypes","existingTemplateSlugs","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","enhancedMissingDefaultTemplateTypes","defaultTaxonomiesMenuItems","taxonomiesMenuItems","defaultPostTypesMenuItems","postTypesMenuItems","authorMenuItem","forEach","menuItem","matchIndex","findIndex","sort","template1","template2","indexOf"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,SACCC,YADD,EAECC,SAFD,EAGCC,QAHD,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,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASlB,KAAK,IAAImB,YAAlB,QAAsC,oBAAtC;AAEA;AACA;AACA;;AACA,OAAOC,sBAAP,MAAmC,6BAAnC;AACA,SACCC,oBADD,EAECC,uBAFD,EAGCC,sBAHD,EAICC,oBAJD,EAKCC,iBALD,EAMCC,2BAND,QAOO,SAPP;AAQA,OAAOC,6BAAP,MAA0C,qCAA1C;AACA,SAASC,UAAT,QAA2B,WAA3B;AACA,SAAS5B,KAAK,IAAI6B,aAAlB,QAAuC,aAAvC;AAEA,MAAMC,sBAAsB,GAAG,CAC9B,YAD8B,EAE9B,QAF8B,EAG9B,MAH8B,E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1B,sBAAsB,CAAC+E,OAAvB,CAAgCD,SAAS,CAACpD,IAA1C,CAFD;AAIA,GALD;AAMA,QAAMqB,gBAAgB,GAAG,CACxB,GAAGmB,mCADqB,EAExB,GAAGtE,2BAA2B,EAFN,EAGxB,GAAG0E,kBAHqB,EAIxB,GAAGF,mBAJqB,CAAzB;AAMA,SAAOrB,gBAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tNavigableMenu,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tarchive,\n\tblockMeta,\n\tcategory,\n\thome,\n\tlist,\n\tmedia,\n\tnotFound,\n\tpage,\n\tpost,\n\tpostAuthor,\n\tpostDate,\n\tsearch,\n\ttag,\n\tlayout as customGenericTemplateIcon,\n} from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport AddCustomTemplateModal from './add-custom-template-modal';\nimport {\n\tuseExistingTemplates,\n\tuseDefaultTemplateTypes,\n\tuseTaxonomiesMenuItems,\n\tusePostTypeMenuItems,\n\tuseAuthorMenuItem,\n\tusePostTypeArchiveMenuItems,\n} from './utils';\nimport AddCustomGenericTemplateModal from './add-custom-generic-template-modal';\nimport { useHistory } from '../routes';\nimport { store as editSiteStore } from '../../store';\n\nconst DEFAULT_TEMPLATE_SLUGS = [\n\t'front-page',\n\t'single',\n\t'page',\n\t'index',\n\t'archive',\n\t'author',\n\t'category',\n\t'date',\n\t'tag',\n\t'taxonomy',\n\t'search',\n\t'404',\n];\n\nconst TEMPLATE_ICONS = {\n\t'front-page': home,\n\tsingle: post,\n\tpage,\n\tarchive,\n\tsearch,\n\t404: notFound,\n\tindex: list,\n\tcategory,\n\tauthor: postAuthor,\n\ttaxonomy: blockMeta,\n\tdate: postDate,\n\ttag,\n\tattachment: media,\n};\n\nexport default function NewTemplate( { postType } ) {\n\tconst [ showCustomTemplateModal, setShowCustomTemplateModal ] =\n\t\tuseState( false );\n\tconst [\n\t\tshowCustomGenericTemplateModal,\n\t\tsetShowCustomGenericTemplateModal,\n\t] = useState( false );\n\tconst [ entityForSuggestions, setEntityForSuggestions ] = useState( {} );\n\n\tconst history = useHistory();\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst { setTemplate } = useDispatch( editSiteStore );\n\n\tasync function createTemplate( template, isWPSuggestion = true ) {\n\t\ttry {\n\t\t\tconst { title, description, slug, templatePrefix } = template;\n\t\t\tlet templateContent = template.content;\n\t\t\t// Try to find fallback content from existing templates.\n\t\t\tif ( ! templateContent ) {\n\t\t\t\tconst fallbackTemplate = await apiFetch( {\n\t\t\t\t\tpath: addQueryArgs( '/wp/v2/templates/lookup', {\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tis_custom: ! isWPSuggestion,\n\t\t\t\t\t\ttemplate_prefix: templatePrefix,\n\t\t\t\t\t} ),\n\t\t\t\t} );\n\t\t\t\ttemplateContent = fallbackTemplate.content;\n\t\t\t}\n\t\t\tconst newTemplate = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tdescription,\n\t\t\t\t\t// Slugs need to be strings, so this is for template `404`\n\t\t\t\t\tslug: slug.toString(),\n\t\t\t\t\tstatus: 'publish',\n\t\t\t\t\ttitle,\n\t\t\t\t\tcontent: templateContent,\n\t\t\t\t\t// This adds a post meta field in template that is part of `is_custom` value calculation.\n\t\t\t\t\tis_wp_suggestion: isWPSuggestion,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\t// Set template before navigating away to avoid initial stale value.\n\t\t\tsetTemplate( newTemplate.id, newTemplate.slug );\n\n\t\t\t// Navigate to the created template editor.\n\t\t\thistory.push( {\n\t\t\t\tpostId: newTemplate.id,\n\t\t\t\tpostType: newTemplate.type,\n\t\t\t} );\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: Title of the created template e.g: \"Category\".\n\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\ttitle\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while creating the template.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t}\n\n\tconst missingTemplates = useMissingTemplates(\n\t\tsetEntityForSuggestions,\n\t\tsetShowCustomTemplateModal\n\t);\n\tif ( ! missingTemplates.length ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<>\n\t\t\t<DropdownMenu\n\t\t\t\tclassName=\"edit-site-new-template-dropdown\"\n\t\t\t\ticon={ null }\n\t\t\t\ttext={ postType.labels.add_new }\n\t\t\t\tlabel={ postType.labels.add_new_item }\n\t\t\t\tpopoverProps={ {\n\t\t\t\t\tnoArrow: false,\n\t\t\t\t} }\n\t\t\t\ttoggleProps={ {\n\t\t\t\t\tvariant: 'primary',\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ () => (\n\t\t\t\t\t<NavigableMenu className=\"edit-site-new-template-dropdown__popover\">\n\t\t\t\t\t\t<MenuGroup label={ postType.labels.add_new_item }>\n\t\t\t\t\t\t\t{ missingTemplates.map( ( template ) => {\n\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t\t\tonClick,\n\t\t\t\t\t\t\t\t\ticon,\n\t\t\t\t\t\t\t\t} = template;\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\t\t\ticon ||\n\t\t\t\t\t\t\t\t\t\t\tTEMPLATE_ICONS[ slug ] ||\n\t\t\t\t\t\t\t\t\t\t\tpost\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\t\tinfo={ description }\n\t\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t\tonClick\n\t\t\t\t\t\t\t\t\t\t\t\t? onClick( template )\n\t\t\t\t\t\t\t\t\t\t\t\t: createTemplate( template )\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ title }\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\ticon={ customGenericTemplateIcon }\n\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\tinfo={ __(\n\t\t\t\t\t\t\t\t\t'Custom templates can be applied to any post or page.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tkey=\"custom-template\"\n\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\tsetShowCustomGenericTemplateModal( true )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Custom template' ) }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t</NavigableMenu>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t\t{ showCustomTemplateModal && (\n\t\t\t\t<AddCustomTemplateModal\n\t\t\t\t\tonClose={ () => setShowCustomTemplateModal( false ) }\n\t\t\t\t\tonSelect={ createTemplate }\n\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showCustomGenericTemplateModal && (\n\t\t\t\t<AddCustomGenericTemplateModal\n\t\t\t\t\tonClose={ () => setShowCustomGenericTemplateModal( false ) }\n\t\t\t\t\tcreateTemplate={ createTemplate }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction useMissingTemplates(\n\tsetEntityForSuggestions,\n\tsetShowCustomTemplateModal\n) {\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst missingDefaultTemplates = ( defaultTemplateTypes || [] ).filter(\n\t\t( template ) =>\n\t\t\tDEFAULT_TEMPLATE_SLUGS.includes( template.slug ) &&\n\t\t\t! existingTemplateSlugs.includes( template.slug )\n\t);\n\tconst onClickMenuItem = ( _entityForSuggestions ) => {\n\t\tsetShowCustomTemplateModal( true );\n\t\tsetEntityForSuggestions( _entityForSuggestions );\n\t};\n\t// We need to replace existing default template types with\n\t// the create specific template functionality. The original\n\t// info (title, description, etc.) is preserved in the\n\t// used hooks.\n\tconst enhancedMissingDefaultTemplateTypes = [ ...missingDefaultTemplates ];\n\tconst { defaultTaxonomiesMenuItems, taxonomiesMenuItems } =\n\t\tuseTaxonomiesMenuItems( onClickMenuItem );\n\tconst { defaultPostTypesMenuItems, postTypesMenuItems } =\n\t\tusePostTypeMenuItems( onClickMenuItem );\n\n\tconst authorMenuItem = useAuthorMenuItem( onClickMenuItem );\n\t[\n\t\t...defaultTaxonomiesMenuItems,\n\t\t...defaultPostTypesMenuItems,\n\t\tauthorMenuItem,\n\t].forEach( ( menuItem ) => {\n\t\tif ( ! menuItem ) {\n\t\t\treturn;\n\t\t}\n\t\tconst matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(\n\t\t\t( template ) => template.slug === menuItem.slug\n\t\t);\n\t\t// Some default template types might have been filtered above from\n\t\t// `missingDefaultTemplates` because they only check for the general\n\t\t// template. So here we either replace or append the item, augmented\n\t\t// with the check if it has available specific item to create a\n\t\t// template for.\n\t\tif ( matchIndex > -1 ) {\n\t\t\tenhancedMissingDefaultTemplateTypes[ matchIndex ] = menuItem;\n\t\t} else {\n\t\t\tenhancedMissingDefaultTemplateTypes.push( menuItem );\n\t\t}\n\t} );\n\t// Update the sort order to match the DEFAULT_TEMPLATE_SLUGS order.\n\tenhancedMissingDefaultTemplateTypes?.sort( ( template1, template2 ) => {\n\t\treturn (\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template1.slug ) -\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template2.slug )\n\t\t);\n\t} );\n\tconst missingTemplates = [\n\t\t...enhancedMissingDefaultTemplateTypes,\n\t\t...usePostTypeArchiveMenuItems(),\n\t\t...postTypesMenuItems,\n\t\t...taxonomiesMenuItems,\n\t];\n\treturn missingTemplates;\n}\n"]}
|