@wordpress/edit-site 4.8.0 → 4.11.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 +6 -0
- package/build/components/add-new-template/add-custom-generic-template-modal.js +84 -0
- package/build/components/add-new-template/add-custom-generic-template-modal.js.map +1 -0
- package/build/components/add-new-template/add-custom-template-modal.js +204 -0
- package/build/components/add-new-template/add-custom-template-modal.js.map +1 -0
- package/build/components/add-new-template/new-template.js +91 -33
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/add-new-template/utils.js +532 -0
- package/build/components/add-new-template/utils.js.map +1 -0
- package/build/components/block-editor/index.js +1 -3
- package/build/components/block-editor/index.js.map +1 -1
- package/build/components/code-editor/index.js +17 -4
- package/build/components/code-editor/index.js.map +1 -1
- package/build/components/editor/index.js +16 -0
- package/build/components/editor/index.js.map +1 -1
- package/build/components/error-boundary/index.js +6 -0
- package/build/components/error-boundary/index.js.map +1 -1
- package/build/components/global-styles/context-menu.js +6 -3
- package/build/components/global-styles/context-menu.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +185 -19
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/global-styles-provider.js +4 -2
- package/build/components/global-styles/global-styles-provider.js.map +1 -1
- package/build/components/global-styles/hooks.js +11 -2
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/palette.js +2 -1
- package/build/components/global-styles/palette.js.map +1 -1
- package/build/components/global-styles/screen-block-list.js +4 -1
- package/build/components/global-styles/screen-block-list.js.map +1 -1
- package/build/components/global-styles/screen-button-color.js +80 -0
- package/build/components/global-styles/screen-button-color.js.map +1 -0
- package/build/components/global-styles/screen-color-palette.js +13 -17
- package/build/components/global-styles/screen-color-palette.js.map +1 -1
- package/build/components/global-styles/screen-colors.js +56 -8
- package/build/components/global-styles/screen-colors.js.map +1 -1
- package/build/components/global-styles/screen-link-color.js +48 -14
- package/build/components/global-styles/screen-link-color.js.map +1 -1
- package/build/components/global-styles/screen-root.js +4 -2
- package/build/components/global-styles/screen-root.js.map +1 -1
- package/build/components/global-styles/screen-typography-element.js +4 -0
- package/build/components/global-styles/screen-typography-element.js.map +1 -1
- package/build/components/global-styles/screen-typography.js +9 -1
- package/build/components/global-styles/screen-typography.js.map +1 -1
- package/build/components/global-styles/ui.js +11 -0
- package/build/components/global-styles/ui.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +282 -35
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +35 -2
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/header/index.js +29 -10
- package/build/components/header/index.js.map +1 -1
- package/build/components/header/more-menu/site-export.js +4 -1
- package/build/components/header/more-menu/site-export.js.map +1 -1
- package/build/components/header/undo-redo/redo.js +13 -4
- package/build/components/header/undo-redo/redo.js.map +1 -1
- package/build/components/header/undo-redo/undo.js +13 -4
- package/build/components/header/undo-redo/undo.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/config.js +17 -0
- package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/index.js +1 -3
- package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build/components/sidebar/template-card/index.js +19 -7
- package/build/components/sidebar/template-card/index.js.map +1 -1
- package/build/components/sidebar/template-card/template-actions.js +64 -0
- package/build/components/sidebar/template-card/template-actions.js.map +1 -0
- package/build/components/template-details/edit-template-title.js +11 -3
- package/build/components/template-details/edit-template-title.js.map +1 -1
- package/build/components/template-details/index.js +1 -20
- package/build/components/template-details/index.js.map +1 -1
- package/build/hooks/index.js +2 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/template-part-edit.js +86 -0
- package/build/hooks/template-part-edit.js.map +1 -0
- package/build/store/selectors.js +4 -1
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/add-new-template/add-custom-generic-template-modal.js +77 -0
- package/build-module/components/add-new-template/add-custom-generic-template-modal.js.map +1 -0
- package/build-module/components/add-new-template/add-custom-template-modal.js +189 -0
- package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -0
- package/build-module/components/add-new-template/new-template.js +90 -34
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +503 -0
- package/build-module/components/add-new-template/utils.js.map +1 -0
- package/build-module/components/block-editor/index.js +1 -2
- package/build-module/components/block-editor/index.js.map +1 -1
- package/build-module/components/code-editor/index.js +18 -5
- package/build-module/components/code-editor/index.js.map +1 -1
- package/build-module/components/editor/index.js +16 -0
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/error-boundary/index.js +5 -0
- package/build-module/components/error-boundary/index.js.map +1 -1
- package/build-module/components/global-styles/context-menu.js +6 -3
- package/build-module/components/global-styles/context-menu.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +185 -20
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/global-styles-provider.js +4 -2
- package/build-module/components/global-styles/global-styles-provider.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +11 -2
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/palette.js +2 -1
- package/build-module/components/global-styles/palette.js.map +1 -1
- package/build-module/components/global-styles/screen-block-list.js +4 -1
- package/build-module/components/global-styles/screen-block-list.js.map +1 -1
- package/build-module/components/global-styles/screen-button-color.js +67 -0
- package/build-module/components/global-styles/screen-button-color.js.map +1 -0
- package/build-module/components/global-styles/screen-color-palette.js +14 -19
- package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
- package/build-module/components/global-styles/screen-colors.js +57 -9
- package/build-module/components/global-styles/screen-colors.js.map +1 -1
- package/build-module/components/global-styles/screen-link-color.js +47 -14
- package/build-module/components/global-styles/screen-link-color.js.map +1 -1
- package/build-module/components/global-styles/screen-root.js +4 -2
- package/build-module/components/global-styles/screen-root.js.map +1 -1
- package/build-module/components/global-styles/screen-typography-element.js +4 -0
- package/build-module/components/global-styles/screen-typography-element.js.map +1 -1
- package/build-module/components/global-styles/screen-typography.js +10 -2
- package/build-module/components/global-styles/screen-typography.js.map +1 -1
- package/build-module/components/global-styles/ui.js +10 -0
- package/build-module/components/global-styles/ui.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +280 -42
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +34 -3
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/header/index.js +31 -11
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/header/more-menu/site-export.js +4 -1
- package/build-module/components/header/more-menu/site-export.js.map +1 -1
- package/build-module/components/header/undo-redo/redo.js +9 -3
- package/build-module/components/header/undo-redo/redo.js.map +1 -1
- package/build-module/components/header/undo-redo/undo.js +9 -3
- package/build-module/components/header/undo-redo/undo.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/config.js +17 -0
- package/build-module/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.js +1 -2
- package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build-module/components/sidebar/template-card/index.js +18 -7
- package/build-module/components/sidebar/template-card/index.js.map +1 -1
- package/build-module/components/sidebar/template-card/template-actions.js +49 -0
- package/build-module/components/sidebar/template-card/template-actions.js.map +1 -0
- package/build-module/components/template-details/edit-template-title.js +12 -3
- package/build-module/components/template-details/edit-template-title.js.map +1 -1
- package/build-module/components/template-details/index.js +2 -21
- package/build-module/components/template-details/index.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/template-part-edit.js +67 -0
- package/build-module/hooks/template-part-edit.js.map +1 -0
- package/build-module/store/selectors.js +5 -2
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +198 -49
- package/build-style/style.css +198 -49
- package/package.json +29 -29
- package/src/components/add-new-template/add-custom-generic-template-modal.js +97 -0
- package/src/components/add-new-template/add-custom-template-modal.js +247 -0
- package/src/components/add-new-template/new-template.js +158 -70
- package/src/components/add-new-template/style.scss +149 -0
- package/src/components/add-new-template/utils.js +538 -0
- package/src/components/block-editor/index.js +0 -2
- package/src/components/code-editor/index.js +15 -5
- package/src/components/editor/index.js +11 -0
- package/src/components/error-boundary/index.js +5 -0
- package/src/components/global-styles/context-menu.js +3 -0
- package/src/components/global-styles/dimensions-panel.js +209 -21
- package/src/components/global-styles/global-styles-provider.js +8 -9
- package/src/components/global-styles/hooks.js +18 -0
- package/src/components/global-styles/palette.js +4 -1
- package/src/components/global-styles/screen-block-list.js +10 -1
- package/src/components/global-styles/screen-button-color.js +102 -0
- package/src/components/global-styles/screen-color-palette.js +25 -27
- package/src/components/global-styles/screen-colors.js +58 -7
- package/src/components/global-styles/screen-link-color.js +65 -23
- package/src/components/global-styles/screen-root.js +8 -2
- package/src/components/global-styles/screen-typography-element.js +4 -0
- package/src/components/global-styles/screen-typography.js +17 -2
- package/src/components/global-styles/style.scss +14 -8
- package/src/components/global-styles/test/use-global-styles-output.js +313 -16
- package/src/components/global-styles/ui.js +13 -0
- package/src/components/global-styles/use-global-styles-output.js +344 -38
- package/src/components/global-styles/utils.js +36 -2
- package/src/components/header/index.js +42 -17
- package/src/components/header/more-menu/site-export.js +3 -0
- package/src/components/header/style.scss +58 -8
- package/src/components/header/undo-redo/redo.js +6 -1
- package/src/components/header/undo-redo/undo.js +6 -1
- package/src/components/keyboard-shortcut-help-modal/config.js +12 -0
- package/src/components/keyboard-shortcut-help-modal/index.js +1 -2
- package/src/components/keyboard-shortcut-help-modal/style.scss +0 -5
- package/src/components/list/style.scss +0 -8
- package/src/components/sidebar/style.scss +4 -0
- package/src/components/sidebar/template-card/index.js +15 -6
- package/src/components/sidebar/template-card/style.scss +49 -35
- package/src/components/sidebar/template-card/template-actions.js +43 -0
- package/src/components/template-details/edit-template-title.js +10 -2
- package/src/components/template-details/index.js +4 -21
- package/src/components/test/error-boundary.js +38 -0
- package/src/hooks/index.js +1 -0
- package/src/hooks/template-part-edit.js +82 -0
- package/src/store/selectors.js +11 -5
- package/src/style.scss +0 -1
- package/build/components/edit-template-part-menu-button/index.js +0 -90
- package/build/components/edit-template-part-menu-button/index.js.map +0 -1
- package/build-module/components/edit-template-part-menu-button/index.js +0 -72
- package/build-module/components/edit-template-part-menu-button/index.js.map +0 -1
- package/src/components/edit-template-part-menu-button/index.js +0 -82
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { createElement } from "@wordpress/element";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
import { kebabCase } from 'lodash';
|
|
7
|
+
/**
|
|
8
|
+
* WordPress dependencies
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { useState } from '@wordpress/element';
|
|
12
|
+
import { __ } from '@wordpress/i18n';
|
|
13
|
+
import { Button, Flex, FlexItem, Modal, TextControl } from '@wordpress/components';
|
|
14
|
+
|
|
15
|
+
function AddCustomGenericTemplateModal(_ref) {
|
|
16
|
+
let {
|
|
17
|
+
onClose,
|
|
18
|
+
createTemplate
|
|
19
|
+
} = _ref;
|
|
20
|
+
const [title, setTitle] = useState('');
|
|
21
|
+
|
|
22
|
+
const defaultTitle = __('Custom Template');
|
|
23
|
+
|
|
24
|
+
const [isBusy, setIsBusy] = useState(false);
|
|
25
|
+
|
|
26
|
+
async function onCreateTemplate(event) {
|
|
27
|
+
event.preventDefault();
|
|
28
|
+
|
|
29
|
+
if (isBusy) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
setIsBusy(true);
|
|
34
|
+
createTemplate({
|
|
35
|
+
slug: 'wp-custom-template-' + kebabCase(title || defaultTitle),
|
|
36
|
+
title: title || defaultTitle
|
|
37
|
+
}, false);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return createElement(Modal, {
|
|
41
|
+
title: __('Create custom template'),
|
|
42
|
+
closeLabel: __('Close'),
|
|
43
|
+
onRequestClose: () => {
|
|
44
|
+
onClose();
|
|
45
|
+
},
|
|
46
|
+
overlayClassName: "edit-site-custom-generic-template__modal"
|
|
47
|
+
}, createElement("form", {
|
|
48
|
+
onSubmit: onCreateTemplate
|
|
49
|
+
}, createElement(Flex, {
|
|
50
|
+
align: "flex-start",
|
|
51
|
+
gap: 8
|
|
52
|
+
}, createElement(FlexItem, null, createElement(TextControl, {
|
|
53
|
+
label: __('Name'),
|
|
54
|
+
value: title,
|
|
55
|
+
onChange: setTitle,
|
|
56
|
+
placeholder: defaultTitle,
|
|
57
|
+
disabled: isBusy,
|
|
58
|
+
help: __('Describe the template, e.g. "Post with sidebar".')
|
|
59
|
+
}))), createElement(Flex, {
|
|
60
|
+
className: "edit-site-custom-generic-template__modal-actions",
|
|
61
|
+
justify: "flex-end",
|
|
62
|
+
expanded: false
|
|
63
|
+
}, createElement(FlexItem, null, createElement(Button, {
|
|
64
|
+
variant: "tertiary",
|
|
65
|
+
onClick: () => {
|
|
66
|
+
onClose();
|
|
67
|
+
}
|
|
68
|
+
}, __('Cancel'))), createElement(FlexItem, null, createElement(Button, {
|
|
69
|
+
variant: "primary",
|
|
70
|
+
type: "submit",
|
|
71
|
+
isBusy: isBusy,
|
|
72
|
+
"aria-disabled": isBusy
|
|
73
|
+
}, __('Create'))))));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export default AddCustomGenericTemplateModal;
|
|
77
|
+
//# sourceMappingURL=add-custom-generic-template-modal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/add-custom-generic-template-modal.js"],"names":["kebabCase","useState","__","Button","Flex","FlexItem","Modal","TextControl","AddCustomGenericTemplateModal","onClose","createTemplate","title","setTitle","defaultTitle","isBusy","setIsBusy","onCreateTemplate","event","preventDefault","slug"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0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GC,IAAA,QAAQ,EAAGC,QAHZ;AAIC,IAAA,WAAW,EAAGC,YAJf;AAKC,IAAA,QAAQ,EAAGC,MALZ;AAMC,IAAA,IAAI,EAAGZ,EAAE,CACR,kDADQ;AANV,IADD,CADD,CADD,EAgBC,cAAC,IAAD;AACC,IAAA,SAAS,EAAC,kDADX;AAEC,IAAA,OAAO,EAAC,UAFT;AAGC,IAAA,QAAQ,EAAG;AAHZ,KAKC,cAAC,QAAD,QACC,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,UADT;AAEC,IAAA,OAAO,EAAG,MAAM;AACfO,MAAAA,OAAO;AACP;AAJF,KAMGP,EAAE,CAAE,QAAF,CANL,CADD,CALD,EAeC,cAAC,QAAD,QACC,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,IAAI,EAAC,QAFN;AAGC,IAAA,MAAM,EAAGY,MAHV;AAIC,qBAAgBA;AAJjB,KAMGZ,EAAE,CAAE,QAAF,CANL,CADD,CAfD,CAhBD,CARD,CADD;AAsDA;;AAED,eAAeM,6BAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { kebabCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tButton,\n\tFlex,\n\tFlexItem,\n\tModal,\n\tTextControl,\n} from '@wordpress/components';\n\nfunction AddCustomGenericTemplateModal( { onClose, createTemplate } ) {\n\tconst [ title, setTitle ] = useState( '' );\n\tconst defaultTitle = __( 'Custom Template' );\n\tconst [ isBusy, setIsBusy ] = useState( false );\n\tasync function onCreateTemplate( event ) {\n\t\tevent.preventDefault();\n\n\t\tif ( isBusy ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsBusy( true );\n\n\t\tcreateTemplate(\n\t\t\t{\n\t\t\t\tslug:\n\t\t\t\t\t'wp-custom-template-' + kebabCase( title || defaultTitle ),\n\t\t\t\ttitle: title || defaultTitle,\n\t\t\t},\n\t\t\tfalse\n\t\t);\n\t}\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ __( 'Create custom template' ) }\n\t\t\tcloseLabel={ __( 'Close' ) }\n\t\t\tonRequestClose={ () => {\n\t\t\t\tonClose();\n\t\t\t} }\n\t\t\toverlayClassName=\"edit-site-custom-generic-template__modal\"\n\t\t>\n\t\t\t<form onSubmit={ onCreateTemplate }>\n\t\t\t\t<Flex align=\"flex-start\" gap={ 8 }>\n\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\t\tplaceholder={ defaultTitle }\n\t\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'Describe the template, e.g. \"Post with sidebar\".'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t</Flex>\n\n\t\t\t\t<Flex\n\t\t\t\t\tclassName=\"edit-site-custom-generic-template__modal-actions\"\n\t\t\t\t\tjustify=\"flex-end\"\n\t\t\t\t\texpanded={ false }\n\t\t\t\t>\n\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\t\taria-disabled={ isBusy }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t</Flex>\n\t\t\t</form>\n\t\t</Modal>\n\t);\n}\n\nexport default AddCustomGenericTemplateModal;\n"]}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { createElement, Fragment } from "@wordpress/element";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* WordPress dependencies
|
|
6
|
+
*/
|
|
7
|
+
import { useState, useMemo, useEffect } from '@wordpress/element';
|
|
8
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
9
|
+
import { Button, Flex, FlexItem, Modal, SearchControl, TextHighlight, __experimentalText as Text, __unstableComposite as Composite, __unstableUseCompositeState as useCompositeState, __unstableCompositeItem as CompositeItem } from '@wordpress/components';
|
|
10
|
+
import { useDebounce } from '@wordpress/compose';
|
|
11
|
+
import { useEntityRecords } from '@wordpress/core-data';
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { mapToIHasNameAndId } from './utils';
|
|
17
|
+
const EMPTY_ARRAY = [];
|
|
18
|
+
|
|
19
|
+
function SuggestionListItem(_ref) {
|
|
20
|
+
let {
|
|
21
|
+
suggestion,
|
|
22
|
+
search,
|
|
23
|
+
onSelect,
|
|
24
|
+
entityForSuggestions,
|
|
25
|
+
composite
|
|
26
|
+
} = _ref;
|
|
27
|
+
const baseCssClass = 'edit-site-custom-template-modal__suggestions_list__list-item';
|
|
28
|
+
return createElement(CompositeItem, _extends({
|
|
29
|
+
role: "option",
|
|
30
|
+
as: Button
|
|
31
|
+
}, composite, {
|
|
32
|
+
className: baseCssClass,
|
|
33
|
+
onClick: () => onSelect(entityForSuggestions.config.getSpecificTemplate(suggestion))
|
|
34
|
+
}), createElement("span", {
|
|
35
|
+
className: `${baseCssClass}__title`
|
|
36
|
+
}, createElement(TextHighlight, {
|
|
37
|
+
text: suggestion.name,
|
|
38
|
+
highlight: search
|
|
39
|
+
})), suggestion.link && createElement("span", {
|
|
40
|
+
className: `${baseCssClass}__info`
|
|
41
|
+
}, suggestion.link));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function useDebouncedInput() {
|
|
45
|
+
const [input, setInput] = useState('');
|
|
46
|
+
const [debounced, setter] = useState('');
|
|
47
|
+
const setDebounced = useDebounce(setter, 250);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (debounced !== input) {
|
|
50
|
+
setDebounced(input);
|
|
51
|
+
}
|
|
52
|
+
}, [debounced, input]);
|
|
53
|
+
return [input, setInput, debounced];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function useSearchSuggestions(entityForSuggestions, search) {
|
|
57
|
+
const {
|
|
58
|
+
config
|
|
59
|
+
} = entityForSuggestions;
|
|
60
|
+
const query = useMemo(() => ({
|
|
61
|
+
order: 'asc',
|
|
62
|
+
context: 'view',
|
|
63
|
+
search,
|
|
64
|
+
per_page: search ? 20 : 10,
|
|
65
|
+
...config.queryArgs(search)
|
|
66
|
+
}), [search, config]);
|
|
67
|
+
const {
|
|
68
|
+
records: searchResults,
|
|
69
|
+
hasResolved: searchHasResolved
|
|
70
|
+
} = useEntityRecords(entityForSuggestions.type, entityForSuggestions.slug, query);
|
|
71
|
+
const [suggestions, setSuggestions] = useState(EMPTY_ARRAY);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (!searchHasResolved) return;
|
|
74
|
+
let newSuggestions = EMPTY_ARRAY;
|
|
75
|
+
|
|
76
|
+
if (searchResults !== null && searchResults !== void 0 && searchResults.length) {
|
|
77
|
+
newSuggestions = searchResults;
|
|
78
|
+
|
|
79
|
+
if (config.recordNamePath) {
|
|
80
|
+
newSuggestions = mapToIHasNameAndId(newSuggestions, config.recordNamePath);
|
|
81
|
+
}
|
|
82
|
+
} // Update suggestions only when the query has resolved, so as to keep
|
|
83
|
+
// the previous results in the UI.
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
setSuggestions(newSuggestions);
|
|
87
|
+
}, [searchResults, searchHasResolved]);
|
|
88
|
+
return suggestions;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function SuggestionList(_ref2) {
|
|
92
|
+
let {
|
|
93
|
+
entityForSuggestions,
|
|
94
|
+
onSelect
|
|
95
|
+
} = _ref2;
|
|
96
|
+
const composite = useCompositeState({
|
|
97
|
+
orientation: 'vertical'
|
|
98
|
+
});
|
|
99
|
+
const [search, setSearch, debouncedSearch] = useDebouncedInput();
|
|
100
|
+
const suggestions = useSearchSuggestions(entityForSuggestions, debouncedSearch);
|
|
101
|
+
const {
|
|
102
|
+
labels
|
|
103
|
+
} = entityForSuggestions;
|
|
104
|
+
const [showSearchControl, setShowSearchControl] = useState(false);
|
|
105
|
+
|
|
106
|
+
if (!showSearchControl && (suggestions === null || suggestions === void 0 ? void 0 : suggestions.length) > 9) {
|
|
107
|
+
setShowSearchControl(true);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return createElement(Fragment, null, showSearchControl && createElement(SearchControl, {
|
|
111
|
+
onChange: setSearch,
|
|
112
|
+
value: search,
|
|
113
|
+
label: labels.search_items,
|
|
114
|
+
placeholder: labels.search_items
|
|
115
|
+
}), !!(suggestions !== null && suggestions !== void 0 && suggestions.length) && createElement(Composite, _extends({}, composite, {
|
|
116
|
+
role: "listbox",
|
|
117
|
+
className: "edit-site-custom-template-modal__suggestions_list",
|
|
118
|
+
"aria-label": __('Suggestions list')
|
|
119
|
+
}), suggestions.map(suggestion => createElement(SuggestionListItem, {
|
|
120
|
+
key: suggestion.slug,
|
|
121
|
+
suggestion: suggestion,
|
|
122
|
+
search: debouncedSearch,
|
|
123
|
+
onSelect: onSelect,
|
|
124
|
+
entityForSuggestions: entityForSuggestions,
|
|
125
|
+
composite: composite
|
|
126
|
+
}))), debouncedSearch && !(suggestions !== null && suggestions !== void 0 && suggestions.length) && createElement("p", {
|
|
127
|
+
className: "edit-site-custom-template-modal__no-results"
|
|
128
|
+
}, labels.not_found));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function AddCustomTemplateModal(_ref3) {
|
|
132
|
+
let {
|
|
133
|
+
onClose,
|
|
134
|
+
onSelect,
|
|
135
|
+
entityForSuggestions
|
|
136
|
+
} = _ref3;
|
|
137
|
+
const [showSearchEntities, setShowSearchEntities] = useState(entityForSuggestions.hasGeneralTemplate);
|
|
138
|
+
const baseCssClass = 'edit-site-custom-template-modal';
|
|
139
|
+
return createElement(Modal, {
|
|
140
|
+
title: sprintf( // translators: %s: Name of the post type e.g: "Post".
|
|
141
|
+
__('Add template: %s'), entityForSuggestions.labels.singular_name),
|
|
142
|
+
className: baseCssClass,
|
|
143
|
+
closeLabel: __('Close'),
|
|
144
|
+
onRequestClose: onClose
|
|
145
|
+
}, !showSearchEntities && createElement(Fragment, null, createElement("p", null, __('Select whether to create a single template for all items or a specific one.')), createElement(Flex, {
|
|
146
|
+
className: `${baseCssClass}__contents`,
|
|
147
|
+
gap: "4",
|
|
148
|
+
align: "initial"
|
|
149
|
+
}, createElement(FlexItem, {
|
|
150
|
+
isBlock: true,
|
|
151
|
+
as: Button,
|
|
152
|
+
onClick: () => {
|
|
153
|
+
const {
|
|
154
|
+
slug,
|
|
155
|
+
title,
|
|
156
|
+
description
|
|
157
|
+
} = entityForSuggestions.template;
|
|
158
|
+
onSelect({
|
|
159
|
+
slug,
|
|
160
|
+
title,
|
|
161
|
+
description
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}, createElement(Text, {
|
|
165
|
+
as: "span",
|
|
166
|
+
weight: 600
|
|
167
|
+
}, entityForSuggestions.labels.all_items), createElement(Text, {
|
|
168
|
+
as: "span"
|
|
169
|
+
}, // translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.
|
|
170
|
+
__('For all items'))), createElement(FlexItem, {
|
|
171
|
+
isBlock: true,
|
|
172
|
+
as: Button,
|
|
173
|
+
onClick: () => {
|
|
174
|
+
setShowSearchEntities(true);
|
|
175
|
+
}
|
|
176
|
+
}, createElement(Text, {
|
|
177
|
+
as: "span",
|
|
178
|
+
weight: 600
|
|
179
|
+
}, entityForSuggestions.labels.singular_name), createElement(Text, {
|
|
180
|
+
as: "span"
|
|
181
|
+
}, // translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.
|
|
182
|
+
__('For a specific item'))))), showSearchEntities && createElement(Fragment, null, createElement("p", null, __('This template will be used only for the specific item chosen.')), createElement(SuggestionList, {
|
|
183
|
+
entityForSuggestions: entityForSuggestions,
|
|
184
|
+
onSelect: onSelect
|
|
185
|
+
})));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export default AddCustomTemplateModal;
|
|
189
|
+
//# sourceMappingURL=add-custom-template-modal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/add-custom-template-modal.js"],"names":["useState","useMemo","useEffect","__","sprintf","Button","Flex","FlexItem","Modal","SearchControl","TextHighlight","__experimentalText","Text","__unstableComposite","Composite","__unstableUseCompositeState","useCompositeState","__unstableCompositeItem","CompositeItem","useDebounce","useEntityRecords","mapToIHasNameAndId","EMPTY_ARRAY","SuggestionListItem","suggestion","search","onSelect","entityForSuggestions","composite","baseCssClass","config","getSpecificTemplate","name","link","useDebouncedInput","input","setInput","debounced","setter","setDebounced","useSearchSuggestions","query","order","context","per_page","queryArgs","records","searchResults","hasResolved","searchHasResolved","type","slug","suggestions","setSuggestions","newSuggestions","length","recordNamePath","SuggestionList","orientation","setSearch","debouncedSearch","labels","showSearchControl","setShowSearchControl","search_items","map","not_found","AddCustomTemplateModal","onClose","showSearchEntities","setShowSearchEntities","hasGeneralTemplate","singular_name","title","description","template","all_items"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,OAAnB,EAA4BC,SAA5B,QAA6C,oBAA7C;AACA,SAASC,EAAT,EAAaC,OAAb,QA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AEC,IAAA,EAAE,EAAGxB,MAFN;AAGC,IAAA,OAAO,EAAG,MAAM;AACf,YAAM;AAAE8C,QAAAA,IAAF;AAAQsB,QAAAA,KAAR;AAAeC,QAAAA;AAAf,UACL/C,oBAAoB,CAACgD,QADtB;AAEAjD,MAAAA,QAAQ,CAAE;AAAEyB,QAAAA,IAAF;AAAQsB,QAAAA,KAAR;AAAeC,QAAAA;AAAf,OAAF,CAAR;AACA;AAPF,KASC,cAAC,IAAD;AAAM,IAAA,EAAE,EAAC,MAAT;AAAgB,IAAA,MAAM,EAAG;AAAzB,KACG/C,oBAAoB,CAACkC,MAArB,CAA4Be,SAD/B,CATD,EAYC,cAAC,IAAD;AAAM,IAAA,EAAE,EAAC;AAAT,KAEE;AACAzE,EAAAA,EAAE,CAAE,eAAF,CAHJ,CAZD,CALD,EAwBC,cAAC,QAAD;AACC,IAAA,OAAO,MADR;AAEC,IAAA,EAAE,EAAGE,MAFN;AAGC,IAAA,OAAO,EAAG,MAAM;AACfiE,MAAAA,qBAAqB,CAAE,IAAF,CAArB;AACA;AALF,KAOC,cAAC,IAAD;AAAM,IAAA,EAAE,EAAC,MAAT;AAAgB,IAAA,MAAM,EAAG;AAAzB,KACG3C,oBAAoB,CAACkC,MAArB,CAA4BW,aAD/B,CAPD,EAUC,cAAC,IAAD;AAAM,IAAA,EAAE,EAAC;AAAT,KAEE;AACArE,EAAAA,EAAE,CAAE,qBAAF,CAHJ,CAVD,CAxBD,CAND,CAXF,EA6DGkE,kBAAkB,IACnB,8BACC,yBACGlE,EAAE,CACH,+DADG,CADL,CADD,EAMC,cAAC,cAAD;AACC,IAAA,oBAAoB,EAAGwB,oBADxB;AAEC,IAAA,QAAQ,EAAGD;AAFZ,IAND,CA9DF,CADD;AA6EA;;AAED,eAAeyC,sBAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useMemo, useEffect } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tButton,\n\tFlex,\n\tFlexItem,\n\tModal,\n\tSearchControl,\n\tTextHighlight,\n\t__experimentalText as Text,\n\t__unstableComposite as Composite,\n\t__unstableUseCompositeState as useCompositeState,\n\t__unstableCompositeItem as CompositeItem,\n} from '@wordpress/components';\nimport { useDebounce } from '@wordpress/compose';\nimport { useEntityRecords } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { mapToIHasNameAndId } from './utils';\n\nconst EMPTY_ARRAY = [];\n\nfunction SuggestionListItem( {\n\tsuggestion,\n\tsearch,\n\tonSelect,\n\tentityForSuggestions,\n\tcomposite,\n} ) {\n\tconst baseCssClass =\n\t\t'edit-site-custom-template-modal__suggestions_list__list-item';\n\treturn (\n\t\t<CompositeItem\n\t\t\trole=\"option\"\n\t\t\tas={ Button }\n\t\t\t{ ...composite }\n\t\t\tclassName={ baseCssClass }\n\t\t\tonClick={ () =>\n\t\t\t\tonSelect(\n\t\t\t\t\tentityForSuggestions.config.getSpecificTemplate(\n\t\t\t\t\t\tsuggestion\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t}\n\t\t>\n\t\t\t<span className={ `${ baseCssClass }__title` }>\n\t\t\t\t<TextHighlight text={ suggestion.name } highlight={ search } />\n\t\t\t</span>\n\t\t\t{ suggestion.link && (\n\t\t\t\t<span className={ `${ baseCssClass }__info` }>\n\t\t\t\t\t{ suggestion.link }\n\t\t\t\t</span>\n\t\t\t) }\n\t\t</CompositeItem>\n\t);\n}\n\nfunction useDebouncedInput() {\n\tconst [ input, setInput ] = useState( '' );\n\tconst [ debounced, setter ] = useState( '' );\n\tconst setDebounced = useDebounce( setter, 250 );\n\tuseEffect( () => {\n\t\tif ( debounced !== input ) {\n\t\t\tsetDebounced( input );\n\t\t}\n\t}, [ debounced, input ] );\n\treturn [ input, setInput, debounced ];\n}\n\nfunction useSearchSuggestions( entityForSuggestions, search ) {\n\tconst { config } = entityForSuggestions;\n\tconst query = useMemo(\n\t\t() => ( {\n\t\t\torder: 'asc',\n\t\t\tcontext: 'view',\n\t\t\tsearch,\n\t\t\tper_page: search ? 20 : 10,\n\t\t\t...config.queryArgs( search ),\n\t\t} ),\n\t\t[ search, config ]\n\t);\n\tconst { records: searchResults, hasResolved: searchHasResolved } =\n\t\tuseEntityRecords(\n\t\t\tentityForSuggestions.type,\n\t\t\tentityForSuggestions.slug,\n\t\t\tquery\n\t\t);\n\tconst [ suggestions, setSuggestions ] = useState( EMPTY_ARRAY );\n\tuseEffect( () => {\n\t\tif ( ! searchHasResolved ) return;\n\t\tlet newSuggestions = EMPTY_ARRAY;\n\t\tif ( searchResults?.length ) {\n\t\t\tnewSuggestions = searchResults;\n\t\t\tif ( config.recordNamePath ) {\n\t\t\t\tnewSuggestions = mapToIHasNameAndId(\n\t\t\t\t\tnewSuggestions,\n\t\t\t\t\tconfig.recordNamePath\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\t// Update suggestions only when the query has resolved, so as to keep\n\t\t// the previous results in the UI.\n\t\tsetSuggestions( newSuggestions );\n\t}, [ searchResults, searchHasResolved ] );\n\treturn suggestions;\n}\n\nfunction SuggestionList( { entityForSuggestions, onSelect } ) {\n\tconst composite = useCompositeState( { orientation: 'vertical' } );\n\tconst [ search, setSearch, debouncedSearch ] = useDebouncedInput();\n\tconst suggestions = useSearchSuggestions(\n\t\tentityForSuggestions,\n\t\tdebouncedSearch\n\t);\n\tconst { labels } = entityForSuggestions;\n\tconst [ showSearchControl, setShowSearchControl ] = useState( false );\n\tif ( ! showSearchControl && suggestions?.length > 9 ) {\n\t\tsetShowSearchControl( true );\n\t}\n\treturn (\n\t\t<>\n\t\t\t{ showSearchControl && (\n\t\t\t\t<SearchControl\n\t\t\t\t\tonChange={ setSearch }\n\t\t\t\t\tvalue={ search }\n\t\t\t\t\tlabel={ labels.search_items }\n\t\t\t\t\tplaceholder={ labels.search_items }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ !! suggestions?.length && (\n\t\t\t\t<Composite\n\t\t\t\t\t{ ...composite }\n\t\t\t\t\trole=\"listbox\"\n\t\t\t\t\tclassName=\"edit-site-custom-template-modal__suggestions_list\"\n\t\t\t\t\taria-label={ __( 'Suggestions list' ) }\n\t\t\t\t>\n\t\t\t\t\t{ suggestions.map( ( suggestion ) => (\n\t\t\t\t\t\t<SuggestionListItem\n\t\t\t\t\t\t\tkey={ suggestion.slug }\n\t\t\t\t\t\t\tsuggestion={ suggestion }\n\t\t\t\t\t\t\tsearch={ debouncedSearch }\n\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\t\tcomposite={ composite }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t</Composite>\n\t\t\t) }\n\t\t\t{ debouncedSearch && ! suggestions?.length && (\n\t\t\t\t<p className=\"edit-site-custom-template-modal__no-results\">\n\t\t\t\t\t{ labels.not_found }\n\t\t\t\t</p>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction AddCustomTemplateModal( { onClose, onSelect, entityForSuggestions } ) {\n\tconst [ showSearchEntities, setShowSearchEntities ] = useState(\n\t\tentityForSuggestions.hasGeneralTemplate\n\t);\n\tconst baseCssClass = 'edit-site-custom-template-modal';\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ sprintf(\n\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t__( 'Add template: %s' ),\n\t\t\t\tentityForSuggestions.labels.singular_name\n\t\t\t) }\n\t\t\tclassName={ baseCssClass }\n\t\t\tcloseLabel={ __( 'Close' ) }\n\t\t\tonRequestClose={ onClose }\n\t\t>\n\t\t\t{ ! showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Select whether to create a single template for all items or a specific one.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t\t<Flex\n\t\t\t\t\t\tclassName={ `${ baseCssClass }__contents` }\n\t\t\t\t\t\tgap=\"4\"\n\t\t\t\t\t\talign=\"initial\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tconst { slug, title, description } =\n\t\t\t\t\t\t\t\t\tentityForSuggestions.template;\n\t\t\t\t\t\t\t\tonSelect( { slug, title, description } );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Text as=\"span\" weight={ 600 }>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.all_items }\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t\t<Text as=\"span\">\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.\n\t\t\t\t\t\t\t\t\t__( 'For all items' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetShowSearchEntities( true );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Text as=\"span\" weight={ 600 }>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.singular_name }\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t\t<Text as=\"span\">\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.\n\t\t\t\t\t\t\t\t\t__( 'For a specific item' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t</Flex>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'This template will be used only for the specific item chosen.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</p>\n\t\t\t\t\t<SuggestionList\n\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</Modal>\n\t);\n}\n\nexport default AddCustomTemplateModal;\n"]}
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
import { createElement } from "@wordpress/element";
|
|
1
|
+
import { createElement, Fragment } from "@wordpress/element";
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* External dependencies
|
|
5
|
-
*/
|
|
6
|
-
import { filter, includes, map } from 'lodash';
|
|
7
3
|
/**
|
|
8
4
|
* WordPress dependencies
|
|
9
5
|
*/
|
|
10
|
-
|
|
11
6
|
import { DropdownMenu, MenuGroup, MenuItem, NavigableMenu } from '@wordpress/components';
|
|
12
|
-
import {
|
|
7
|
+
import { useState } from '@wordpress/element';
|
|
8
|
+
import { useDispatch } from '@wordpress/data';
|
|
13
9
|
import { store as coreStore } from '@wordpress/core-data';
|
|
14
|
-
import {
|
|
15
|
-
import { archive, blockMeta, category, home, list, media, notFound, page, post, postAuthor, postDate, search, tag } from '@wordpress/icons';
|
|
10
|
+
import { archive, blockMeta, category, home, list, media, notFound, page, post, postAuthor, postDate, search, tag, layout as customGenericTemplateIcon } from '@wordpress/icons';
|
|
16
11
|
import { __ } from '@wordpress/i18n';
|
|
17
12
|
import { store as noticesStore } from '@wordpress/notices';
|
|
18
13
|
/**
|
|
19
14
|
* Internal dependencies
|
|
20
15
|
*/
|
|
21
16
|
|
|
17
|
+
import AddCustomTemplateModal from './add-custom-template-modal';
|
|
18
|
+
import { useExistingTemplates, useDefaultTemplateTypes, useTaxonomiesMenuItems, usePostTypeMenuItems } from './utils';
|
|
19
|
+
import AddCustomGenericTemplateModal from './add-custom-generic-template-modal';
|
|
22
20
|
import { useHistory } from '../routes';
|
|
23
21
|
import { store as editSiteStore } from '../../store';
|
|
24
22
|
const DEFAULT_TEMPLATE_SLUGS = ['front-page', 'single', 'page', 'index', 'archive', 'author', 'category', 'date', 'tag', 'taxonomy', 'search', '404'];
|
|
@@ -41,16 +39,10 @@ export default function NewTemplate(_ref) {
|
|
|
41
39
|
let {
|
|
42
40
|
postType
|
|
43
41
|
} = _ref;
|
|
42
|
+
const [showCustomTemplateModal, setShowCustomTemplateModal] = useState(false);
|
|
43
|
+
const [showCustomGenericTemplateModal, setShowCustomGenericTemplateModal] = useState(false);
|
|
44
|
+
const [entityForSuggestions, setEntityForSuggestions] = useState({});
|
|
44
45
|
const history = useHistory();
|
|
45
|
-
const {
|
|
46
|
-
templates,
|
|
47
|
-
defaultTemplateTypes
|
|
48
|
-
} = useSelect(select => ({
|
|
49
|
-
templates: select(coreStore).getEntityRecords('postType', 'wp_template', {
|
|
50
|
-
per_page: -1
|
|
51
|
-
}),
|
|
52
|
-
defaultTemplateTypes: select(editorStore).__experimentalGetDefaultTemplateTypes()
|
|
53
|
-
}), []);
|
|
54
46
|
const {
|
|
55
47
|
saveEntityRecord
|
|
56
48
|
} = useDispatch(coreStore);
|
|
@@ -62,6 +54,8 @@ export default function NewTemplate(_ref) {
|
|
|
62
54
|
} = useDispatch(editSiteStore);
|
|
63
55
|
|
|
64
56
|
async function createTemplate(template) {
|
|
57
|
+
let isWPSuggestion = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
58
|
+
|
|
65
59
|
try {
|
|
66
60
|
const {
|
|
67
61
|
title,
|
|
@@ -75,7 +69,7 @@ export default function NewTemplate(_ref) {
|
|
|
75
69
|
status: 'publish',
|
|
76
70
|
title,
|
|
77
71
|
// This adds a post meta field in template that is part of `is_custom` value calculation.
|
|
78
|
-
is_wp_suggestion:
|
|
72
|
+
is_wp_suggestion: isWPSuggestion
|
|
79
73
|
}, {
|
|
80
74
|
throwOnError: true
|
|
81
75
|
}); // Set template before navigating away to avoid initial stale value.
|
|
@@ -94,18 +88,13 @@ export default function NewTemplate(_ref) {
|
|
|
94
88
|
}
|
|
95
89
|
}
|
|
96
90
|
|
|
97
|
-
const
|
|
98
|
-
const missingTemplates = filter(defaultTemplateTypes, template => includes(DEFAULT_TEMPLATE_SLUGS, template.slug) && !includes(existingTemplateSlugs, template.slug));
|
|
91
|
+
const missingTemplates = useMissingTemplates(setEntityForSuggestions, setShowCustomTemplateModal);
|
|
99
92
|
|
|
100
93
|
if (!missingTemplates.length) {
|
|
101
94
|
return null;
|
|
102
|
-
}
|
|
103
|
-
|
|
95
|
+
}
|
|
104
96
|
|
|
105
|
-
|
|
106
|
-
return DEFAULT_TEMPLATE_SLUGS.indexOf(template1.slug) - DEFAULT_TEMPLATE_SLUGS.indexOf(template2.slug);
|
|
107
|
-
});
|
|
108
|
-
return createElement(DropdownMenu, {
|
|
97
|
+
return createElement(Fragment, null, createElement(DropdownMenu, {
|
|
109
98
|
className: "edit-site-new-template-dropdown",
|
|
110
99
|
icon: null,
|
|
111
100
|
text: postType.labels.add_new,
|
|
@@ -120,21 +109,88 @@ export default function NewTemplate(_ref) {
|
|
|
120
109
|
className: "edit-site-new-template-dropdown__popover"
|
|
121
110
|
}, createElement(MenuGroup, {
|
|
122
111
|
label: postType.labels.add_new_item
|
|
123
|
-
}, map(
|
|
112
|
+
}, missingTemplates.map(template => {
|
|
124
113
|
const {
|
|
125
114
|
title,
|
|
126
115
|
description,
|
|
127
|
-
slug
|
|
116
|
+
slug,
|
|
117
|
+
onClick,
|
|
118
|
+
icon
|
|
128
119
|
} = template;
|
|
129
120
|
return createElement(MenuItem, {
|
|
130
|
-
icon: TEMPLATE_ICONS[slug],
|
|
121
|
+
icon: icon || TEMPLATE_ICONS[slug] || post,
|
|
131
122
|
iconPosition: "left",
|
|
132
123
|
info: description,
|
|
133
124
|
key: slug,
|
|
134
|
-
onClick: () =>
|
|
135
|
-
createTemplate(template); // We will be navigated way so no need to close the dropdown.
|
|
136
|
-
}
|
|
125
|
+
onClick: () => onClick ? onClick(template) : createTemplate(template)
|
|
137
126
|
}, title);
|
|
138
|
-
}))
|
|
127
|
+
})), createElement(MenuGroup, null, createElement(MenuItem, {
|
|
128
|
+
icon: customGenericTemplateIcon,
|
|
129
|
+
iconPosition: "left",
|
|
130
|
+
info: __('Custom templates can be applied to any post or page.'),
|
|
131
|
+
key: "custom-template",
|
|
132
|
+
onClick: () => setShowCustomGenericTemplateModal(true)
|
|
133
|
+
}, __('Custom template'))))), showCustomTemplateModal && createElement(AddCustomTemplateModal, {
|
|
134
|
+
onClose: () => setShowCustomTemplateModal(false),
|
|
135
|
+
onSelect: createTemplate,
|
|
136
|
+
entityForSuggestions: entityForSuggestions
|
|
137
|
+
}), showCustomGenericTemplateModal && createElement(AddCustomGenericTemplateModal, {
|
|
138
|
+
onClose: () => setShowCustomGenericTemplateModal(false),
|
|
139
|
+
createTemplate: createTemplate
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function useMissingTemplates(setEntityForSuggestions, setShowCustomTemplateModal) {
|
|
144
|
+
const existingTemplates = useExistingTemplates();
|
|
145
|
+
const defaultTemplateTypes = useDefaultTemplateTypes();
|
|
146
|
+
const existingTemplateSlugs = (existingTemplates || []).map(_ref2 => {
|
|
147
|
+
let {
|
|
148
|
+
slug
|
|
149
|
+
} = _ref2;
|
|
150
|
+
return slug;
|
|
151
|
+
});
|
|
152
|
+
const missingDefaultTemplates = (defaultTemplateTypes || []).filter(template => DEFAULT_TEMPLATE_SLUGS.includes(template.slug) && !existingTemplateSlugs.includes(template.slug));
|
|
153
|
+
|
|
154
|
+
const onClickMenuItem = _entityForSuggestions => {
|
|
155
|
+
setShowCustomTemplateModal(true);
|
|
156
|
+
setEntityForSuggestions(_entityForSuggestions);
|
|
157
|
+
}; // We need to replace existing default template types with
|
|
158
|
+
// the create specific template functionality. The original
|
|
159
|
+
// info (title, description, etc.) is preserved in the
|
|
160
|
+
// used hooks.
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
const enhancedMissingDefaultTemplateTypes = [...missingDefaultTemplates];
|
|
164
|
+
const {
|
|
165
|
+
defaultTaxonomiesMenuItems,
|
|
166
|
+
taxonomiesMenuItems
|
|
167
|
+
} = useTaxonomiesMenuItems(onClickMenuItem);
|
|
168
|
+
const {
|
|
169
|
+
defaultPostTypesMenuItems,
|
|
170
|
+
postTypesMenuItems
|
|
171
|
+
} = usePostTypeMenuItems(onClickMenuItem);
|
|
172
|
+
[...defaultTaxonomiesMenuItems, ...defaultPostTypesMenuItems].forEach(menuItem => {
|
|
173
|
+
if (!menuItem) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(template => template.slug === menuItem.slug); // Some default template types might have been filtered above from
|
|
178
|
+
// `missingDefaultTemplates` because they only check for the general
|
|
179
|
+
// template. So here we either replace or append the item, augmented
|
|
180
|
+
// with the check if it has available specific item to create a
|
|
181
|
+
// template for.
|
|
182
|
+
|
|
183
|
+
if (matchIndex > -1) {
|
|
184
|
+
enhancedMissingDefaultTemplateTypes[matchIndex] = menuItem;
|
|
185
|
+
} else {
|
|
186
|
+
enhancedMissingDefaultTemplateTypes.push(menuItem);
|
|
187
|
+
}
|
|
188
|
+
}); // Update the sort order to match the DEFAULT_TEMPLATE_SLUGS order.
|
|
189
|
+
|
|
190
|
+
enhancedMissingDefaultTemplateTypes === null || enhancedMissingDefaultTemplateTypes === void 0 ? void 0 : enhancedMissingDefaultTemplateTypes.sort((template1, template2) => {
|
|
191
|
+
return DEFAULT_TEMPLATE_SLUGS.indexOf(template1.slug) - DEFAULT_TEMPLATE_SLUGS.indexOf(template2.slug);
|
|
192
|
+
});
|
|
193
|
+
const missingTemplates = [...enhancedMissingDefaultTemplateTypes, ...postTypesMenuItems, ...taxonomiesMenuItems];
|
|
194
|
+
return missingTemplates;
|
|
139
195
|
}
|
|
140
196
|
//# sourceMappingURL=new-template.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["filter","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","single","index","author","taxonomy","date","attachment","NewTemplate","postType","history","templates","defaultTemplateTypes","select","getEntityRecords","per_page","__experimentalGetDefaultTemplateTypes","saveEntityRecord","createErrorNotice","setTemplate","createTemplate","template","title","description","slug","newTemplate","toString","status","is_wp_suggestion","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,QAAjB,EAA2BC,GAA3B,QAAsC,QAAtC;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,IAAIm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fJ,QAAAA,cAAc,CAAEC,QAAF,CAAd,CADe,CAEf;AACA;AARF,OAUGC,KAVH,CADD;AAcA,GAhBI,CADN,CADD,CAbF,CADD;AAsCA","sourcesContent":["/**\n * External dependencies\n */\nimport { filter, 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',\n\t'page',\n\t'index',\n\t'archive',\n\t'author',\n\t'category',\n\t'date',\n\t'tag',\n\t'taxonomy',\n\t'search',\n\t'404',\n];\n\nconst TEMPLATE_ICONS = {\n\t'front-page': home,\n\tsingle: post,\n\tpage,\n\tarchive,\n\tsearch,\n\t404: notFound,\n\tindex: list,\n\tcategory,\n\tauthor: postAuthor,\n\ttaxonomy: blockMeta,\n\tdate: postDate,\n\ttag,\n\tattachment: media,\n};\n\nexport default function NewTemplate( { postType } ) {\n\tconst history = useHistory();\n\tconst { 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:\n\t\t\t\tselect( editorStore ).__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( template ) {\n\t\ttry {\n\t\t\tconst { title, description, slug } = template;\n\n\t\t\tconst newTemplate = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tdescription,\n\t\t\t\t\t// Slugs need to be strings, so this is for template `404`\n\t\t\t\t\tslug: slug.toString(),\n\t\t\t\t\tstatus: 'publish',\n\t\t\t\t\ttitle,\n\t\t\t\t\t// This adds a post meta field in template that is part of `is_custom` value calculation.\n\t\t\t\t\tis_wp_suggestion: true,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\t// Set template before navigating away to avoid initial stale value.\n\t\t\tsetTemplate( newTemplate.id, newTemplate.slug );\n\n\t\t\t// Navigate to the created template editor.\n\t\t\thistory.push( {\n\t\t\t\tpostId: newTemplate.id,\n\t\t\t\tpostType: newTemplate.type,\n\t\t\t} );\n\n\t\t\t// TODO: Add a success notice?\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while creating the template.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t}\n\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( missingTemplates, ( template ) => {\n\t\t\t\t\t\t\tconst { title, description, slug } = template;\n\t\t\t\t\t\t\treturn (\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( template );\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"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["DropdownMenu","MenuGroup","MenuItem","NavigableMenu","useState","useDispatch","store","coreStore","archive","blockMeta","category","home","list","media","notFound","page","post","postAuthor","postDate","search","tag","layout","customGenericTemplateIcon","__","noticesStore","AddCustomTemplateModal","useExistingTemplates","useDefaultTemplateTypes","useTaxonomiesMenuItems","usePostTypeMenuItems","AddCustomGenericTemplateModal","useHistory","editSiteStore","DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","single","index","author","taxonomy","date","attachment","NewTemplate","postType","showCustomTemplateModal","setShowCustomTemplateModal","showCustomGenericTemplateModal","setShowCustomGenericTemplateModal","entityForSuggestions","setEntityForSuggestions","history","saveEntityRecord","createErrorNotice","setTemplate","createTemplate","template","isWPSuggestion","title","description","slug","newTemplate","toString","status","is_wp_suggestion","throwOnError","id","push","postId","type","error","errorMessage","message","code","missingTemplates","useMissingTemplates","length","labels","add_new","add_new_item","noArrow","variant","map","onClick","icon","existingTemplates","defaultTemplateTypes","existingTemplateSlugs","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","enhancedMissingDefaultTemplateTypes","defaultTaxonomiesMenuItems","taxonomiesMenuItems","defaultPostTypesMenuItems","postTypesMenuItems","forEach","menuItem","matchIndex","findIndex","sort","template1","template2","indexOf"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,YADD,EAECC,SAFD,EAGCC,QAHD,EAICC,aAJD,QAKO,uBALP;AAMA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,WAAT,QAA4B,iBAA5B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SACCC,OADD,EAECC,SAFD,EAGCC,QAHD,EAICC,IAJD,EAKCC,IALD,EAMCC,KAND,EAOCC,QAPD,EAQCC,IARD,EASCC,IATD,EAUCC,UAVD,EAWCC,QAXD,EAYCC,MAZD,EAaCC,GAbD,EAcCC,MAAM,IAAIC,yBAdX,QAeO,kBAfP;AAgBA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASjB,KAAK,IAAIkB,YAAlB,QAAsC,oBAAtC;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5C;AACA,QAAM;AAAEM,IAAAA,0BAAF;AAA8BC,IAAAA;AAA9B,MACLjE,sBAAsB,CAAE6D,eAAF,CADvB;AAEA,QAAM;AAAEK,IAAAA,yBAAF;AAA6BC,IAAAA;AAA7B,MACLlE,oBAAoB,CAAE4D,eAAF,CADrB;AAEA,GAAE,GAAGG,0BAAL,EAAiC,GAAGE,yBAApC,EAAgEE,OAAhE,CACGC,QAAF,IAAgB;AACf,QAAK,CAAEA,QAAP,EAAkB;AACjB;AACA;;AACD,UAAMC,UAAU,GAAGP,mCAAmC,CAACQ,SAApC,CAChB7C,QAAF,IAAgBA,QAAQ,CAACI,IAAT,KAAkBuC,QAAQ,CAACvC,IADzB,CAAnB,CAJe,CAOf;AACA;AACA;AACA;AACA;;AACA,QAAKwC,UAAU,GAAG,CAAC,CAAnB,EAAuB;AACtBP,MAAAA,mCAAmC,CAAEO,UAAF,CAAnC,GAAoDD,QAApD;AACA,KAFD,MAEO;AACNN,MAAAA,mCAAmC,CAAC1B,IAApC,CAA0CgC,QAA1C;AACA;AACD,GAlBF,EAxBC,CA4CD;;AACAN,EAAAA,mCAAmC,SAAnC,IAAAA,mCAAmC,WAAnC,YAAAA,mCAAmC,CAAES,IAArC,CAA2C,CAAEC,SAAF,EAAaC,SAAb,KAA4B;AACtE,WACCrE,sBAAsB,CAACsE,OAAvB,CAAgCF,SAAS,CAAC3C,IAA1C,IACAzB,sBAAsB,CAACsE,OAAvB,CAAgCD,SAAS,CAAC5C,IAA1C,CAFD;AAIA,GALD;AAMA,QAAMc,gBAAgB,GAAG,CACxB,GAAGmB,mCADqB,EAExB,GAAGI,kBAFqB,EAGxB,GAAGF,mBAHqB,CAAzB;AAKA,SAAOrB,gBAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tNavigableMenu,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tarchive,\n\tblockMeta,\n\tcategory,\n\thome,\n\tlist,\n\tmedia,\n\tnotFound,\n\tpage,\n\tpost,\n\tpostAuthor,\n\tpostDate,\n\tsearch,\n\ttag,\n\tlayout as customGenericTemplateIcon,\n} from '@wordpress/icons';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport AddCustomTemplateModal from './add-custom-template-modal';\nimport {\n\tuseExistingTemplates,\n\tuseDefaultTemplateTypes,\n\tuseTaxonomiesMenuItems,\n\tusePostTypeMenuItems,\n} from './utils';\nimport AddCustomGenericTemplateModal from './add-custom-generic-template-modal';\nimport { useHistory } from '../routes';\nimport { store as editSiteStore } from '../../store';\n\nconst DEFAULT_TEMPLATE_SLUGS = [\n\t'front-page',\n\t'single',\n\t'page',\n\t'index',\n\t'archive',\n\t'author',\n\t'category',\n\t'date',\n\t'tag',\n\t'taxonomy',\n\t'search',\n\t'404',\n];\n\nconst TEMPLATE_ICONS = {\n\t'front-page': home,\n\tsingle: post,\n\tpage,\n\tarchive,\n\tsearch,\n\t404: notFound,\n\tindex: list,\n\tcategory,\n\tauthor: postAuthor,\n\ttaxonomy: blockMeta,\n\tdate: postDate,\n\ttag,\n\tattachment: media,\n};\n\nexport default function NewTemplate( { postType } ) {\n\tconst [ showCustomTemplateModal, setShowCustomTemplateModal ] =\n\t\tuseState( false );\n\tconst [\n\t\tshowCustomGenericTemplateModal,\n\t\tsetShowCustomGenericTemplateModal,\n\t] = useState( false );\n\tconst [ entityForSuggestions, setEntityForSuggestions ] = useState( {} );\n\n\tconst history = useHistory();\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst { setTemplate } = useDispatch( editSiteStore );\n\n\tasync function createTemplate( template, isWPSuggestion = true ) {\n\t\ttry {\n\t\t\tconst { title, description, slug } = template;\n\t\t\tconst newTemplate = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tdescription,\n\t\t\t\t\t// Slugs need to be strings, so this is for template `404`\n\t\t\t\t\tslug: slug.toString(),\n\t\t\t\t\tstatus: 'publish',\n\t\t\t\t\ttitle,\n\t\t\t\t\t// This adds a post meta field in template that is part of `is_custom` value calculation.\n\t\t\t\t\tis_wp_suggestion: isWPSuggestion,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\t// Set template before navigating away to avoid initial stale value.\n\t\t\tsetTemplate( newTemplate.id, newTemplate.slug );\n\n\t\t\t// Navigate to the created template editor.\n\t\t\thistory.push( {\n\t\t\t\tpostId: newTemplate.id,\n\t\t\t\tpostType: newTemplate.type,\n\t\t\t} );\n\n\t\t\t// TODO: Add a success notice?\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while creating the template.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t}\n\n\tconst missingTemplates = useMissingTemplates(\n\t\tsetEntityForSuggestions,\n\t\tsetShowCustomTemplateModal\n\t);\n\tif ( ! missingTemplates.length ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<>\n\t\t\t<DropdownMenu\n\t\t\t\tclassName=\"edit-site-new-template-dropdown\"\n\t\t\t\ticon={ null }\n\t\t\t\ttext={ postType.labels.add_new }\n\t\t\t\tlabel={ postType.labels.add_new_item }\n\t\t\t\tpopoverProps={ {\n\t\t\t\t\tnoArrow: false,\n\t\t\t\t} }\n\t\t\t\ttoggleProps={ {\n\t\t\t\t\tvariant: 'primary',\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ () => (\n\t\t\t\t\t<NavigableMenu className=\"edit-site-new-template-dropdown__popover\">\n\t\t\t\t\t\t<MenuGroup label={ postType.labels.add_new_item }>\n\t\t\t\t\t\t\t{ missingTemplates.map( ( template ) => {\n\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t\t\tonClick,\n\t\t\t\t\t\t\t\t\ticon,\n\t\t\t\t\t\t\t\t} = template;\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\t\t\ticon ||\n\t\t\t\t\t\t\t\t\t\t\tTEMPLATE_ICONS[ slug ] ||\n\t\t\t\t\t\t\t\t\t\t\tpost\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\t\tinfo={ description }\n\t\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t\tonClick\n\t\t\t\t\t\t\t\t\t\t\t\t? onClick( template )\n\t\t\t\t\t\t\t\t\t\t\t\t: createTemplate( template )\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ title }\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\ticon={ customGenericTemplateIcon }\n\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\tinfo={ __(\n\t\t\t\t\t\t\t\t\t'Custom templates can be applied to any post or page.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tkey=\"custom-template\"\n\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\tsetShowCustomGenericTemplateModal( true )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Custom template' ) }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t</NavigableMenu>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t\t{ showCustomTemplateModal && (\n\t\t\t\t<AddCustomTemplateModal\n\t\t\t\t\tonClose={ () => setShowCustomTemplateModal( false ) }\n\t\t\t\t\tonSelect={ createTemplate }\n\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showCustomGenericTemplateModal && (\n\t\t\t\t<AddCustomGenericTemplateModal\n\t\t\t\t\tonClose={ () => setShowCustomGenericTemplateModal( false ) }\n\t\t\t\t\tcreateTemplate={ createTemplate }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction useMissingTemplates(\n\tsetEntityForSuggestions,\n\tsetShowCustomTemplateModal\n) {\n\tconst 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\t[ ...defaultTaxonomiesMenuItems, ...defaultPostTypesMenuItems ].forEach(\n\t\t( menuItem ) => {\n\t\t\tif ( ! menuItem ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(\n\t\t\t\t( template ) => template.slug === menuItem.slug\n\t\t\t);\n\t\t\t// Some default template types might have been filtered above from\n\t\t\t// `missingDefaultTemplates` because they only check for the general\n\t\t\t// template. So here we either replace or append the item, augmented\n\t\t\t// with the check if it has available specific item to create a\n\t\t\t// template for.\n\t\t\tif ( matchIndex > -1 ) {\n\t\t\t\tenhancedMissingDefaultTemplateTypes[ matchIndex ] = menuItem;\n\t\t\t} else {\n\t\t\t\tenhancedMissingDefaultTemplateTypes.push( menuItem );\n\t\t\t}\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"]}
|