@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
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _element = require("@wordpress/element");
|
|
9
|
+
|
|
10
|
+
var _lodash = require("lodash");
|
|
11
|
+
|
|
12
|
+
var _i18n = require("@wordpress/i18n");
|
|
13
|
+
|
|
14
|
+
var _components = require("@wordpress/components");
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* External dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* WordPress dependencies
|
|
22
|
+
*/
|
|
23
|
+
function AddCustomGenericTemplateModal(_ref) {
|
|
24
|
+
let {
|
|
25
|
+
onClose,
|
|
26
|
+
createTemplate
|
|
27
|
+
} = _ref;
|
|
28
|
+
const [title, setTitle] = (0, _element.useState)('');
|
|
29
|
+
const defaultTitle = (0, _i18n.__)('Custom Template');
|
|
30
|
+
const [isBusy, setIsBusy] = (0, _element.useState)(false);
|
|
31
|
+
|
|
32
|
+
async function onCreateTemplate(event) {
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
|
|
35
|
+
if (isBusy) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setIsBusy(true);
|
|
40
|
+
createTemplate({
|
|
41
|
+
slug: 'wp-custom-template-' + (0, _lodash.kebabCase)(title || defaultTitle),
|
|
42
|
+
title: title || defaultTitle
|
|
43
|
+
}, false);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return (0, _element.createElement)(_components.Modal, {
|
|
47
|
+
title: (0, _i18n.__)('Create custom template'),
|
|
48
|
+
closeLabel: (0, _i18n.__)('Close'),
|
|
49
|
+
onRequestClose: () => {
|
|
50
|
+
onClose();
|
|
51
|
+
},
|
|
52
|
+
overlayClassName: "edit-site-custom-generic-template__modal"
|
|
53
|
+
}, (0, _element.createElement)("form", {
|
|
54
|
+
onSubmit: onCreateTemplate
|
|
55
|
+
}, (0, _element.createElement)(_components.Flex, {
|
|
56
|
+
align: "flex-start",
|
|
57
|
+
gap: 8
|
|
58
|
+
}, (0, _element.createElement)(_components.FlexItem, null, (0, _element.createElement)(_components.TextControl, {
|
|
59
|
+
label: (0, _i18n.__)('Name'),
|
|
60
|
+
value: title,
|
|
61
|
+
onChange: setTitle,
|
|
62
|
+
placeholder: defaultTitle,
|
|
63
|
+
disabled: isBusy,
|
|
64
|
+
help: (0, _i18n.__)('Describe the template, e.g. "Post with sidebar".')
|
|
65
|
+
}))), (0, _element.createElement)(_components.Flex, {
|
|
66
|
+
className: "edit-site-custom-generic-template__modal-actions",
|
|
67
|
+
justify: "flex-end",
|
|
68
|
+
expanded: false
|
|
69
|
+
}, (0, _element.createElement)(_components.FlexItem, null, (0, _element.createElement)(_components.Button, {
|
|
70
|
+
variant: "tertiary",
|
|
71
|
+
onClick: () => {
|
|
72
|
+
onClose();
|
|
73
|
+
}
|
|
74
|
+
}, (0, _i18n.__)('Cancel'))), (0, _element.createElement)(_components.FlexItem, null, (0, _element.createElement)(_components.Button, {
|
|
75
|
+
variant: "primary",
|
|
76
|
+
type: "submit",
|
|
77
|
+
isBusy: isBusy,
|
|
78
|
+
"aria-disabled": isBusy
|
|
79
|
+
}, (0, _i18n.__)('Create'))))));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
var _default = AddCustomGenericTemplateModal;
|
|
83
|
+
exports.default = _default;
|
|
84
|
+
//# 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":["AddCustomGenericTemplateModal","onClose","createTemplate","title","setTitle","defaultTitle","isBusy","setIsBusy","onCreateTemplate","event","preventDefault","slug"],"mappings":";;;;;;;AAQA;;AALA;;AAMA;;AACA;;AAVA;AACA;AACA;;AAGA;AACA;AACA;AAWA,SAASA,6BAAT,OAAsE;AAAA,MAA9B;AAAEC,IAAAA,OAAF;AAAWC,IAAAA;AAAX,GAA8B;AACrE,QAAM,CAAEC,KAAF,EAASC,QAAT,IAAsB,uBAAU,EAAV,CAA5B;AACA,QAAMC,YAAY,GAAG,cAAI,iBAAJ,CAArB;AACA,QAAM,CAAEC,MAAF,EAAUC,SAAV,IAAwB,uBAAU,KAAV,CAA9B;;AACA,iBAAeC,gBAAf,CAAiCC,KAAjC,EAAyC;AACxCA,IAAAA,KAAK,CAACC,cAAN;;AAEA,QAAKJ,MAAL,EAAc;AACb;AACA;;AAEDC,IAAAA,SAAS,CAAE,IAAF,CAAT;AAEAL,IAAAA,cAAc,CACb;AACCS,MAAAA,IAAI,EACH,wBAAwB,uBAAWR,KAAK,IAAIE,YAApB,CAF1B;AAGCF,MAAAA,KAAK,EAAEA,KAAK,IAAIE;AAHjB,KADa,EAMb,KANa,CAAd;AAQA;;AACD,SACC,4BAAC,iBAAD;AACC,IAAA,KAAK,EAAG,cAAI,wBAAJ,CADT;AAEC,IAAA,UAAU,EAAG,cAAI,OAAJ,CAFd;AAGC,IAAA,cAAc,EAAG,MAAM;AACtBJ,MAAAA,OAAO;AACP,KALF;AAMC,IAAA,gBAAgB,EAAC;AANlB,KAQC;AAAM,IAAA,QAAQ,EAAGO;AAAjB,KACC,4BAAC,gBAAD;AAAM,IAAA,KAAK,EAAC,YAAZ;AAAyB,IAAA,GAAG,EAAG;AAA/B,KACC,4BAAC,oBAAD,QACC,4BAAC,uBAAD;AACC,IAAA,KAAK,EAAG,cAAI,MAAJ,CADT;AAEC,IAAA,KAAK,EAAGL,KAFT;AAGC,IAAA,QAAQ,EAAGC,QAHZ;AAIC,IAAA,WAAW,EAAGC,YAJf;AAKC,IAAA,QAAQ,EAAGC,MALZ;AAMC,IAAA,IAAI,EAAG,cACN,kDADM;AANR,IADD,CADD,CADD,EAgBC,4BAAC,gBAAD;AACC,IAAA,SAAS,EAAC,kDADX;AAEC,IAAA,OAAO,EAAC,UAFT;AAGC,IAAA,QAAQ,EAAG;AAHZ,KAKC,4BAAC,oBAAD,QACC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,UADT;AAEC,IAAA,OAAO,EAAG,MAAM;AACfL,MAAAA,OAAO;AACP;AAJF,KAMG,cAAI,QAAJ,CANH,CADD,CALD,EAeC,4BAAC,oBAAD,QACC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,IAAI,EAAC,QAFN;AAGC,IAAA,MAAM,EAAGK,MAHV;AAIC,qBAAgBA;AAJjB,KAMG,cAAI,QAAJ,CANH,CADD,CAfD,CAhBD,CARD,CADD;AAsDA;;eAEcN,6B","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,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _element = require("@wordpress/element");
|
|
11
|
+
|
|
12
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
+
|
|
14
|
+
var _i18n = require("@wordpress/i18n");
|
|
15
|
+
|
|
16
|
+
var _components = require("@wordpress/components");
|
|
17
|
+
|
|
18
|
+
var _compose = require("@wordpress/compose");
|
|
19
|
+
|
|
20
|
+
var _coreData = require("@wordpress/core-data");
|
|
21
|
+
|
|
22
|
+
var _utils = require("./utils");
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* WordPress dependencies
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Internal dependencies
|
|
30
|
+
*/
|
|
31
|
+
const EMPTY_ARRAY = [];
|
|
32
|
+
|
|
33
|
+
function SuggestionListItem(_ref) {
|
|
34
|
+
let {
|
|
35
|
+
suggestion,
|
|
36
|
+
search,
|
|
37
|
+
onSelect,
|
|
38
|
+
entityForSuggestions,
|
|
39
|
+
composite
|
|
40
|
+
} = _ref;
|
|
41
|
+
const baseCssClass = 'edit-site-custom-template-modal__suggestions_list__list-item';
|
|
42
|
+
return (0, _element.createElement)(_components.__unstableCompositeItem, (0, _extends2.default)({
|
|
43
|
+
role: "option",
|
|
44
|
+
as: _components.Button
|
|
45
|
+
}, composite, {
|
|
46
|
+
className: baseCssClass,
|
|
47
|
+
onClick: () => onSelect(entityForSuggestions.config.getSpecificTemplate(suggestion))
|
|
48
|
+
}), (0, _element.createElement)("span", {
|
|
49
|
+
className: `${baseCssClass}__title`
|
|
50
|
+
}, (0, _element.createElement)(_components.TextHighlight, {
|
|
51
|
+
text: suggestion.name,
|
|
52
|
+
highlight: search
|
|
53
|
+
})), suggestion.link && (0, _element.createElement)("span", {
|
|
54
|
+
className: `${baseCssClass}__info`
|
|
55
|
+
}, suggestion.link));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function useDebouncedInput() {
|
|
59
|
+
const [input, setInput] = (0, _element.useState)('');
|
|
60
|
+
const [debounced, setter] = (0, _element.useState)('');
|
|
61
|
+
const setDebounced = (0, _compose.useDebounce)(setter, 250);
|
|
62
|
+
(0, _element.useEffect)(() => {
|
|
63
|
+
if (debounced !== input) {
|
|
64
|
+
setDebounced(input);
|
|
65
|
+
}
|
|
66
|
+
}, [debounced, input]);
|
|
67
|
+
return [input, setInput, debounced];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function useSearchSuggestions(entityForSuggestions, search) {
|
|
71
|
+
const {
|
|
72
|
+
config
|
|
73
|
+
} = entityForSuggestions;
|
|
74
|
+
const query = (0, _element.useMemo)(() => ({
|
|
75
|
+
order: 'asc',
|
|
76
|
+
context: 'view',
|
|
77
|
+
search,
|
|
78
|
+
per_page: search ? 20 : 10,
|
|
79
|
+
...config.queryArgs(search)
|
|
80
|
+
}), [search, config]);
|
|
81
|
+
const {
|
|
82
|
+
records: searchResults,
|
|
83
|
+
hasResolved: searchHasResolved
|
|
84
|
+
} = (0, _coreData.useEntityRecords)(entityForSuggestions.type, entityForSuggestions.slug, query);
|
|
85
|
+
const [suggestions, setSuggestions] = (0, _element.useState)(EMPTY_ARRAY);
|
|
86
|
+
(0, _element.useEffect)(() => {
|
|
87
|
+
if (!searchHasResolved) return;
|
|
88
|
+
let newSuggestions = EMPTY_ARRAY;
|
|
89
|
+
|
|
90
|
+
if (searchResults !== null && searchResults !== void 0 && searchResults.length) {
|
|
91
|
+
newSuggestions = searchResults;
|
|
92
|
+
|
|
93
|
+
if (config.recordNamePath) {
|
|
94
|
+
newSuggestions = (0, _utils.mapToIHasNameAndId)(newSuggestions, config.recordNamePath);
|
|
95
|
+
}
|
|
96
|
+
} // Update suggestions only when the query has resolved, so as to keep
|
|
97
|
+
// the previous results in the UI.
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
setSuggestions(newSuggestions);
|
|
101
|
+
}, [searchResults, searchHasResolved]);
|
|
102
|
+
return suggestions;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function SuggestionList(_ref2) {
|
|
106
|
+
let {
|
|
107
|
+
entityForSuggestions,
|
|
108
|
+
onSelect
|
|
109
|
+
} = _ref2;
|
|
110
|
+
const composite = (0, _components.__unstableUseCompositeState)({
|
|
111
|
+
orientation: 'vertical'
|
|
112
|
+
});
|
|
113
|
+
const [search, setSearch, debouncedSearch] = useDebouncedInput();
|
|
114
|
+
const suggestions = useSearchSuggestions(entityForSuggestions, debouncedSearch);
|
|
115
|
+
const {
|
|
116
|
+
labels
|
|
117
|
+
} = entityForSuggestions;
|
|
118
|
+
const [showSearchControl, setShowSearchControl] = (0, _element.useState)(false);
|
|
119
|
+
|
|
120
|
+
if (!showSearchControl && (suggestions === null || suggestions === void 0 ? void 0 : suggestions.length) > 9) {
|
|
121
|
+
setShowSearchControl(true);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return (0, _element.createElement)(_element.Fragment, null, showSearchControl && (0, _element.createElement)(_components.SearchControl, {
|
|
125
|
+
onChange: setSearch,
|
|
126
|
+
value: search,
|
|
127
|
+
label: labels.search_items,
|
|
128
|
+
placeholder: labels.search_items
|
|
129
|
+
}), !!(suggestions !== null && suggestions !== void 0 && suggestions.length) && (0, _element.createElement)(_components.__unstableComposite, (0, _extends2.default)({}, composite, {
|
|
130
|
+
role: "listbox",
|
|
131
|
+
className: "edit-site-custom-template-modal__suggestions_list",
|
|
132
|
+
"aria-label": (0, _i18n.__)('Suggestions list')
|
|
133
|
+
}), suggestions.map(suggestion => (0, _element.createElement)(SuggestionListItem, {
|
|
134
|
+
key: suggestion.slug,
|
|
135
|
+
suggestion: suggestion,
|
|
136
|
+
search: debouncedSearch,
|
|
137
|
+
onSelect: onSelect,
|
|
138
|
+
entityForSuggestions: entityForSuggestions,
|
|
139
|
+
composite: composite
|
|
140
|
+
}))), debouncedSearch && !(suggestions !== null && suggestions !== void 0 && suggestions.length) && (0, _element.createElement)("p", {
|
|
141
|
+
className: "edit-site-custom-template-modal__no-results"
|
|
142
|
+
}, labels.not_found));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function AddCustomTemplateModal(_ref3) {
|
|
146
|
+
let {
|
|
147
|
+
onClose,
|
|
148
|
+
onSelect,
|
|
149
|
+
entityForSuggestions
|
|
150
|
+
} = _ref3;
|
|
151
|
+
const [showSearchEntities, setShowSearchEntities] = (0, _element.useState)(entityForSuggestions.hasGeneralTemplate);
|
|
152
|
+
const baseCssClass = 'edit-site-custom-template-modal';
|
|
153
|
+
return (0, _element.createElement)(_components.Modal, {
|
|
154
|
+
title: (0, _i18n.sprintf)( // translators: %s: Name of the post type e.g: "Post".
|
|
155
|
+
(0, _i18n.__)('Add template: %s'), entityForSuggestions.labels.singular_name),
|
|
156
|
+
className: baseCssClass,
|
|
157
|
+
closeLabel: (0, _i18n.__)('Close'),
|
|
158
|
+
onRequestClose: onClose
|
|
159
|
+
}, !showSearchEntities && (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)("p", null, (0, _i18n.__)('Select whether to create a single template for all items or a specific one.')), (0, _element.createElement)(_components.Flex, {
|
|
160
|
+
className: `${baseCssClass}__contents`,
|
|
161
|
+
gap: "4",
|
|
162
|
+
align: "initial"
|
|
163
|
+
}, (0, _element.createElement)(_components.FlexItem, {
|
|
164
|
+
isBlock: true,
|
|
165
|
+
as: _components.Button,
|
|
166
|
+
onClick: () => {
|
|
167
|
+
const {
|
|
168
|
+
slug,
|
|
169
|
+
title,
|
|
170
|
+
description
|
|
171
|
+
} = entityForSuggestions.template;
|
|
172
|
+
onSelect({
|
|
173
|
+
slug,
|
|
174
|
+
title,
|
|
175
|
+
description
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}, (0, _element.createElement)(_components.__experimentalText, {
|
|
179
|
+
as: "span",
|
|
180
|
+
weight: 600
|
|
181
|
+
}, entityForSuggestions.labels.all_items), (0, _element.createElement)(_components.__experimentalText, {
|
|
182
|
+
as: "span"
|
|
183
|
+
}, // 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.
|
|
184
|
+
(0, _i18n.__)('For all items'))), (0, _element.createElement)(_components.FlexItem, {
|
|
185
|
+
isBlock: true,
|
|
186
|
+
as: _components.Button,
|
|
187
|
+
onClick: () => {
|
|
188
|
+
setShowSearchEntities(true);
|
|
189
|
+
}
|
|
190
|
+
}, (0, _element.createElement)(_components.__experimentalText, {
|
|
191
|
+
as: "span",
|
|
192
|
+
weight: 600
|
|
193
|
+
}, entityForSuggestions.labels.singular_name), (0, _element.createElement)(_components.__experimentalText, {
|
|
194
|
+
as: "span"
|
|
195
|
+
}, // 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.
|
|
196
|
+
(0, _i18n.__)('For a specific item'))))), showSearchEntities && (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)("p", null, (0, _i18n.__)('This template will be used only for the specific item chosen.')), (0, _element.createElement)(SuggestionList, {
|
|
197
|
+
entityForSuggestions: entityForSuggestions,
|
|
198
|
+
onSelect: onSelect
|
|
199
|
+
})));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
var _default = AddCustomTemplateModal;
|
|
203
|
+
exports.default = _default;
|
|
204
|
+
//# 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":["EMPTY_ARRAY","SuggestionListItem","suggestion","search","onSelect","entityForSuggestions","composite","baseCssClass","Button","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":";;;;;;;;;AAGA;;;;AACA;;AACA;;AAYA;;AACA;;AAKA;;AAvBA;AACA;AACA;;AAkBA;AACA;AACA;AAGA,MAAMA,WAAW,GAAG,EAApB;;AAEA,SAASC,kBAAT,OAMI;AAAA,MANyB;AAC5BC,IAAAA,UAD4B;AAE5BC,IAAAA,MAF4B;AAG5BC,IAAAA,QAH4B;AAI5BC,IAAAA,oBAJ4B;AAK5BC,IAAAA;AAL4B,GAMzB;AACH,QAAMC,YAAY,GACjB,8DADD;AAEA,SACC,4BAAC,mCAAD;AACC,IAAA,IAAI,EAAC,QADN;AAEC,IAAA,EAAE,EAAGC;AAFN,KAGMF,SAHN;AAIC,IAAA,SAAS,EAAGC,YAJb;AAKC,IAAA,OAAO,EAAG,MACTH,QAAQ,CACPC,oBAAoB,CAACI,MAArB,CAA4BC,mBAA5B,CACCR,UADD,CADO;AANV,MAaC;AAAM,IAAA,SAAS,EAAI,GAAGK,YAAc;AAApC,KACC,4BAAC,yBAAD;AAAe,IAAA,IAAI,EAAGL,UAAU,CAACS,IAAjC;AAAwC,IAAA,SAAS,EAAGR;AAApD,IADD,CAbD,EAgBGD,UAAU,CAACU,IAAX,IACD;AAAM,IAAA,SAAS,EAAI,GAAGL,YAAc;AAApC,KAC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,4BAAC,oBAAD;AACC,IAAA,OAAO,MADR;AAEC,IAAA,EAAE,EAAGC,kBAFN;AAGC,IAAA,OAAO,EAAG,MAAM;AACf,YAAM;AAAEsB,QAAAA,IAAF;AAAQsB,QAAAA,KAAR;AAAeC,QAAAA;AAAf,UACLhD,oBAAoB,CAACiD,QADtB;AAEAlD,MAAAA,QAAQ,CAAE;AAAE0B,QAAAA,IAAF;AAAQsB,QAAAA,KAAR;AAAeC,QAAAA;AAAf,OAAF,CAAR;AACA;AAPF,KASC,4BAAC,8BAAD;AAAM,IAAA,EAAE,EAAC,MAAT;AAAgB,IAAA,MAAM,EAAG;AAAzB,KACGhD,oBAAoB,CAACmC,MAArB,CAA4Be,SAD/B,CATD,EAYC,4BAAC,8BAAD;AAAM,IAAA,EAAE,EAAC;AAAT,KAEE;AACA,gBAAI,eAAJ,CAHF,CAZD,CALD,EAwBC,4BAAC,oBAAD;AACC,IAAA,OAAO,MADR;AAEC,IAAA,EAAE,EAAG/C,kBAFN;AAGC,IAAA,OAAO,EAAG,MAAM;AACfyC,MAAAA,qBAAqB,CAAE,IAAF,CAArB;AACA;AALF,KAOC,4BAAC,8BAAD;AAAM,IAAA,EAAE,EAAC,MAAT;AAAgB,IAAA,MAAM,EAAG;AAAzB,KACG5C,oBAAoB,CAACmC,MAArB,CAA4BW,aAD/B,CAPD,EAUC,4BAAC,8BAAD;AAAM,IAAA,EAAE,EAAC;AAAT,KAEE;AACA,gBAAI,qBAAJ,CAHF,CAVD,CAxBD,CAND,CAXF,EA6DGH,kBAAkB,IACnB,qDACC,uCACG,cACD,+DADC,CADH,CADD,EAMC,4BAAC,cAAD;AACC,IAAA,oBAAoB,EAAG3C,oBADxB;AAEC,IAAA,QAAQ,EAAGD;AAFZ,IAND,CA9DF,CADD;AA6EA;;eAEc0C,sB","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,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
@@ -7,30 +9,28 @@ exports.default = NewTemplate;
|
|
|
7
9
|
|
|
8
10
|
var _element = require("@wordpress/element");
|
|
9
11
|
|
|
10
|
-
var _lodash = require("lodash");
|
|
11
|
-
|
|
12
12
|
var _components = require("@wordpress/components");
|
|
13
13
|
|
|
14
14
|
var _data = require("@wordpress/data");
|
|
15
15
|
|
|
16
16
|
var _coreData = require("@wordpress/core-data");
|
|
17
17
|
|
|
18
|
-
var _editor = require("@wordpress/editor");
|
|
19
|
-
|
|
20
18
|
var _icons = require("@wordpress/icons");
|
|
21
19
|
|
|
22
20
|
var _i18n = require("@wordpress/i18n");
|
|
23
21
|
|
|
24
22
|
var _notices = require("@wordpress/notices");
|
|
25
23
|
|
|
24
|
+
var _addCustomTemplateModal = _interopRequireDefault(require("./add-custom-template-modal"));
|
|
25
|
+
|
|
26
|
+
var _utils = require("./utils");
|
|
27
|
+
|
|
28
|
+
var _addCustomGenericTemplateModal = _interopRequireDefault(require("./add-custom-generic-template-modal"));
|
|
29
|
+
|
|
26
30
|
var _routes = require("../routes");
|
|
27
31
|
|
|
28
32
|
var _store = require("../../store");
|
|
29
33
|
|
|
30
|
-
/**
|
|
31
|
-
* External dependencies
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
34
|
/**
|
|
35
35
|
* WordPress dependencies
|
|
36
36
|
*/
|
|
@@ -59,16 +59,10 @@ function NewTemplate(_ref) {
|
|
|
59
59
|
let {
|
|
60
60
|
postType
|
|
61
61
|
} = _ref;
|
|
62
|
+
const [showCustomTemplateModal, setShowCustomTemplateModal] = (0, _element.useState)(false);
|
|
63
|
+
const [showCustomGenericTemplateModal, setShowCustomGenericTemplateModal] = (0, _element.useState)(false);
|
|
64
|
+
const [entityForSuggestions, setEntityForSuggestions] = (0, _element.useState)({});
|
|
62
65
|
const history = (0, _routes.useHistory)();
|
|
63
|
-
const {
|
|
64
|
-
templates,
|
|
65
|
-
defaultTemplateTypes
|
|
66
|
-
} = (0, _data.useSelect)(select => ({
|
|
67
|
-
templates: select(_coreData.store).getEntityRecords('postType', 'wp_template', {
|
|
68
|
-
per_page: -1
|
|
69
|
-
}),
|
|
70
|
-
defaultTemplateTypes: select(_editor.store).__experimentalGetDefaultTemplateTypes()
|
|
71
|
-
}), []);
|
|
72
66
|
const {
|
|
73
67
|
saveEntityRecord
|
|
74
68
|
} = (0, _data.useDispatch)(_coreData.store);
|
|
@@ -80,6 +74,8 @@ function NewTemplate(_ref) {
|
|
|
80
74
|
} = (0, _data.useDispatch)(_store.store);
|
|
81
75
|
|
|
82
76
|
async function createTemplate(template) {
|
|
77
|
+
let isWPSuggestion = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
78
|
+
|
|
83
79
|
try {
|
|
84
80
|
const {
|
|
85
81
|
title,
|
|
@@ -93,7 +89,7 @@ function NewTemplate(_ref) {
|
|
|
93
89
|
status: 'publish',
|
|
94
90
|
title,
|
|
95
91
|
// This adds a post meta field in template that is part of `is_custom` value calculation.
|
|
96
|
-
is_wp_suggestion:
|
|
92
|
+
is_wp_suggestion: isWPSuggestion
|
|
97
93
|
}, {
|
|
98
94
|
throwOnError: true
|
|
99
95
|
}); // Set template before navigating away to avoid initial stale value.
|
|
@@ -112,18 +108,13 @@ function NewTemplate(_ref) {
|
|
|
112
108
|
}
|
|
113
109
|
}
|
|
114
110
|
|
|
115
|
-
const
|
|
116
|
-
const missingTemplates = (0, _lodash.filter)(defaultTemplateTypes, template => (0, _lodash.includes)(DEFAULT_TEMPLATE_SLUGS, template.slug) && !(0, _lodash.includes)(existingTemplateSlugs, template.slug));
|
|
111
|
+
const missingTemplates = useMissingTemplates(setEntityForSuggestions, setShowCustomTemplateModal);
|
|
117
112
|
|
|
118
113
|
if (!missingTemplates.length) {
|
|
119
114
|
return null;
|
|
120
|
-
}
|
|
121
|
-
|
|
115
|
+
}
|
|
122
116
|
|
|
123
|
-
|
|
124
|
-
return DEFAULT_TEMPLATE_SLUGS.indexOf(template1.slug) - DEFAULT_TEMPLATE_SLUGS.indexOf(template2.slug);
|
|
125
|
-
});
|
|
126
|
-
return (0, _element.createElement)(_components.DropdownMenu, {
|
|
117
|
+
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_components.DropdownMenu, {
|
|
127
118
|
className: "edit-site-new-template-dropdown",
|
|
128
119
|
icon: null,
|
|
129
120
|
text: postType.labels.add_new,
|
|
@@ -138,21 +129,88 @@ function NewTemplate(_ref) {
|
|
|
138
129
|
className: "edit-site-new-template-dropdown__popover"
|
|
139
130
|
}, (0, _element.createElement)(_components.MenuGroup, {
|
|
140
131
|
label: postType.labels.add_new_item
|
|
141
|
-
},
|
|
132
|
+
}, missingTemplates.map(template => {
|
|
142
133
|
const {
|
|
143
134
|
title,
|
|
144
135
|
description,
|
|
145
|
-
slug
|
|
136
|
+
slug,
|
|
137
|
+
onClick,
|
|
138
|
+
icon
|
|
146
139
|
} = template;
|
|
147
140
|
return (0, _element.createElement)(_components.MenuItem, {
|
|
148
|
-
icon: TEMPLATE_ICONS[slug],
|
|
141
|
+
icon: icon || TEMPLATE_ICONS[slug] || _icons.post,
|
|
149
142
|
iconPosition: "left",
|
|
150
143
|
info: description,
|
|
151
144
|
key: slug,
|
|
152
|
-
onClick: () =>
|
|
153
|
-
createTemplate(template); // We will be navigated way so no need to close the dropdown.
|
|
154
|
-
}
|
|
145
|
+
onClick: () => onClick ? onClick(template) : createTemplate(template)
|
|
155
146
|
}, title);
|
|
156
|
-
}))))
|
|
147
|
+
})), (0, _element.createElement)(_components.MenuGroup, null, (0, _element.createElement)(_components.MenuItem, {
|
|
148
|
+
icon: _icons.layout,
|
|
149
|
+
iconPosition: "left",
|
|
150
|
+
info: (0, _i18n.__)('Custom templates can be applied to any post or page.'),
|
|
151
|
+
key: "custom-template",
|
|
152
|
+
onClick: () => setShowCustomGenericTemplateModal(true)
|
|
153
|
+
}, (0, _i18n.__)('Custom template'))))), showCustomTemplateModal && (0, _element.createElement)(_addCustomTemplateModal.default, {
|
|
154
|
+
onClose: () => setShowCustomTemplateModal(false),
|
|
155
|
+
onSelect: createTemplate,
|
|
156
|
+
entityForSuggestions: entityForSuggestions
|
|
157
|
+
}), showCustomGenericTemplateModal && (0, _element.createElement)(_addCustomGenericTemplateModal.default, {
|
|
158
|
+
onClose: () => setShowCustomGenericTemplateModal(false),
|
|
159
|
+
createTemplate: createTemplate
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function useMissingTemplates(setEntityForSuggestions, setShowCustomTemplateModal) {
|
|
164
|
+
const existingTemplates = (0, _utils.useExistingTemplates)();
|
|
165
|
+
const defaultTemplateTypes = (0, _utils.useDefaultTemplateTypes)();
|
|
166
|
+
const existingTemplateSlugs = (existingTemplates || []).map(_ref2 => {
|
|
167
|
+
let {
|
|
168
|
+
slug
|
|
169
|
+
} = _ref2;
|
|
170
|
+
return slug;
|
|
171
|
+
});
|
|
172
|
+
const missingDefaultTemplates = (defaultTemplateTypes || []).filter(template => DEFAULT_TEMPLATE_SLUGS.includes(template.slug) && !existingTemplateSlugs.includes(template.slug));
|
|
173
|
+
|
|
174
|
+
const onClickMenuItem = _entityForSuggestions => {
|
|
175
|
+
setShowCustomTemplateModal(true);
|
|
176
|
+
setEntityForSuggestions(_entityForSuggestions);
|
|
177
|
+
}; // We need to replace existing default template types with
|
|
178
|
+
// the create specific template functionality. The original
|
|
179
|
+
// info (title, description, etc.) is preserved in the
|
|
180
|
+
// used hooks.
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
const enhancedMissingDefaultTemplateTypes = [...missingDefaultTemplates];
|
|
184
|
+
const {
|
|
185
|
+
defaultTaxonomiesMenuItems,
|
|
186
|
+
taxonomiesMenuItems
|
|
187
|
+
} = (0, _utils.useTaxonomiesMenuItems)(onClickMenuItem);
|
|
188
|
+
const {
|
|
189
|
+
defaultPostTypesMenuItems,
|
|
190
|
+
postTypesMenuItems
|
|
191
|
+
} = (0, _utils.usePostTypeMenuItems)(onClickMenuItem);
|
|
192
|
+
[...defaultTaxonomiesMenuItems, ...defaultPostTypesMenuItems].forEach(menuItem => {
|
|
193
|
+
if (!menuItem) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(template => template.slug === menuItem.slug); // Some default template types might have been filtered above from
|
|
198
|
+
// `missingDefaultTemplates` because they only check for the general
|
|
199
|
+
// template. So here we either replace or append the item, augmented
|
|
200
|
+
// with the check if it has available specific item to create a
|
|
201
|
+
// template for.
|
|
202
|
+
|
|
203
|
+
if (matchIndex > -1) {
|
|
204
|
+
enhancedMissingDefaultTemplateTypes[matchIndex] = menuItem;
|
|
205
|
+
} else {
|
|
206
|
+
enhancedMissingDefaultTemplateTypes.push(menuItem);
|
|
207
|
+
}
|
|
208
|
+
}); // Update the sort order to match the DEFAULT_TEMPLATE_SLUGS order.
|
|
209
|
+
|
|
210
|
+
enhancedMissingDefaultTemplateTypes === null || enhancedMissingDefaultTemplateTypes === void 0 ? void 0 : enhancedMissingDefaultTemplateTypes.sort((template1, template2) => {
|
|
211
|
+
return DEFAULT_TEMPLATE_SLUGS.indexOf(template1.slug) - DEFAULT_TEMPLATE_SLUGS.indexOf(template2.slug);
|
|
212
|
+
});
|
|
213
|
+
const missingTemplates = [...enhancedMissingDefaultTemplateTypes, ...postTypesMenuItems, ...taxonomiesMenuItems];
|
|
214
|
+
return missingTemplates;
|
|
157
215
|
}
|
|
158
216
|
//# sourceMappingURL=new-template.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","home","single","post","page","archive","search","notFound","index","list","category","author","postAuthor","taxonomy","blockMeta","date","postDate","tag","attachment","media","NewTemplate","postType","history","templates","defaultTemplateTypes","select","coreStore","getEntityRecords","per_page","editorStore","__experimentalGetDefaultTemplateTypes","saveEntityRecord","createErrorNotice","noticesStore","setTemplate","editSiteStore","createTemplate","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":";;;;;;;;;AAGA;;AAKA;;AAMA;;AACA;;AACA;;AACA;;AAeA;;AACA;;AAKA;;AACA;;AAvCA;AACA;AACA;;AAGA;AACA;AACA;;AA4BA;AACA;AACA;AAIA,MAAMA,sBAAsB,GAAG,CAC9B,YAD8B,EAE9B,QAF8B,EAG9B,MAH8B,EAI9B,OAJ8B,EAK9B,SAL8B,EAM9B,QAN8B,EAO9B,UAP8B,EAQ9B,MAR8B,EAS9B,KAT8B,EAU9B,UAV8B,EAW9B,QAX8B,EAY9B,KAZ8B,CAA/B;AAeA,MAAMC,cAAc,GAAG;AACtB,gBAAcC,WADQ;AAEtBC,EAAAA,MAAM,EAAEC,WAFc;AAGtBC,EAAAA,IAAI,EAAJA,WAHsB;AAItBC,EAAAA,OAAO,EAAPA,cAJsB;AAKtBC,EAAAA,MAAM,EAANA,aALsB;AAMtB,OAAKC,eAN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SAAS,EAAC,iCADX;AAEC,IAAA,IAAI,EAAG,IAFR;AAGC,IAAA,IAAI,EAAGnB,QAAQ,CAACwC,MAAT,CAAgBC,OAHxB;AAIC,IAAA,KAAK,EAAGzC,QAAQ,CAACwC,MAAT,CAAgBE,YAJzB;AAKC,IAAA,YAAY,EAAG;AACdC,MAAAA,OAAO,EAAE;AADK,KALhB;AAQC,IAAA,WAAW,EAAG;AACbC,MAAAA,OAAO,EAAE;AADI;AARf,KAYG,MACD,4BAAC,yBAAD;AAAe,IAAA,SAAS,EAAC;AAAzB,KACC,4BAAC,qBAAD;AAAW,IAAA,KAAK,EAAG5C,QAAQ,CAACwC,MAAT,CAAgBE;AAAnC,KACG,iBAAKR,gBAAL,EAAyBlB,QAAF,IAAgB;AACxC,UAAM;AAAEC,MAAAA,KAAF;AAASC,MAAAA,WAAT;AAAsBC,MAAAA;AAAtB,QAA+BH,QAArC;AACA,WACC,4BAAC,oBAAD;AACC,MAAA,IAAI,EAAGrC,cAAc,CAAEwC,IAAF,CADtB;AAEC,MAAA,YAAY,EAAC,MAFd;AAGC,MAAA,IAAI,EAAGD,WAHR;AAIC,MAAA,GAAG,EAAGC,IAJP;AAKC,MAAA,OAAO,EAAG,MAAM;AACfJ,QAAAA,cAAc,CAAEC,QAAF,CAAd,CADe,CAEf;AACA;AARF,OAUGC,KAVH,CADD;AAcA,GAhBC,CADH,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":["DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","home","single","post","page","archive","search","notFound","index","list","category","author","postAuthor","taxonomy","blockMeta","date","postDate","tag","attachment","media","NewTemplate","postType","showCustomTemplateModal","setShowCustomTemplateModal","showCustomGenericTemplateModal","setShowCustomGenericTemplateModal","entityForSuggestions","setEntityForSuggestions","history","saveEntityRecord","coreStore","createErrorNotice","noticesStore","setTemplate","editSiteStore","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","customGenericTemplateIcon","existingTemplates","defaultTemplateTypes","existingTemplateSlugs","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","enhancedMissingDefaultTemplateTypes","defaultTaxonomiesMenuItems","taxonomiesMenuItems","defaultPostTypesMenuItems","postTypesMenuItems","forEach","menuItem","matchIndex","findIndex","sort","template1","template2","indexOf"],"mappings":";;;;;;;;;AASA;;AANA;;AAOA;;AACA;;AACA;;AAgBA;;AACA;;AAKA;;AACA;;AAMA;;AACA;;AACA;;AA3CA;AACA;AACA;;AA6BA;AACA;AACA;AAYA,MAAMA,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,MAAMC,cAAc,GAAG;AACtB,gBAAcC,WADQ;AAEtBC,EAAAA,MAAM,EAAEC,WAFc;AAGtBC,EAAAA,IAAI,EAAJA,WAHsB;AAItBC,EAAAA,OAAO,EAAPA,cAJsB;AAKtBC,EAAAA,MAAM,EAANA,aALsB;AAMtB,OAAKC,eANiB;AAOtBC,EAAAA,KAAK,EAAEC,WAPe;AAQtBC,EAAAA,QAAQ,EAARA,eARsB;AAStBC,EAAAA,MAAM,EAAEC,iBATc;AAUtBC,EAAAA,QAAQ,EAAEC,gBAVY;AAWtBC,EAAAA,IAAI,EAAEC,eAXgB;AAYtBC,EAAAA,GAAG,EAAHA,UAZsB;AAatBC,EAAAA,UAAU,EAAEC;AAbU,CAAvB;;AAgBe,SAASC,WAAT,OAAqC;AAAA,MAAf;AAAEC,IAAAA;AAAF,GAAe;AACnD,QAAM,CAAEC,uBAAF,EAA2BC,0BAA3B,IACL,uBAAU,KAAV,CADD;AAEA,QAAM,CACLC,8BADK,EAELC,iCAFK,IAGF,uBAAU,KAAV,CAHJ;AAIA,QAAM,CAAEC,oBAAF,EAAwBC,uBAAxB,IAAoD,uBAAU,EAAV,CAA1D;AAEA,QAAMC,OAAO,GAAG,yBAAhB;AACA,QAAM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AA,0BAAF;AAA8BC,IAAAA;AAA9B,MACL,mCAAwBJ,eAAxB,CADD;AAEA,QAAM;AAAEK,IAAAA,yBAAF;AAA6BC,IAAAA;AAA7B,MACL,iCAAsBN,eAAtB,CADD;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,CAChB9C,QAAF,IAAgBA,QAAQ,CAACI,IAAT,KAAkBwC,QAAQ,CAACxC,IADzB,CAAnB,CAJe,CAOf;AACA;AACA;AACA;AACA;;AACA,QAAKyC,UAAU,GAAG,CAAC,CAAnB,EAAuB;AACtBP,MAAAA,mCAAmC,CAAEO,UAAF,CAAnC,GAAoDD,QAApD;AACA,KAFD,MAEO;AACNN,MAAAA,mCAAmC,CAAC3B,IAApC,CAA0CiC,QAA1C;AACA;AACD,GAlBF,EAxBC,CA4CD;;AACAN,EAAAA,mCAAmC,SAAnC,IAAAA,mCAAmC,WAAnC,YAAAA,mCAAmC,CAAES,IAArC,CAA2C,CAAEC,SAAF,EAAaC,SAAb,KAA4B;AACtE,WACCtF,sBAAsB,CAACuF,OAAvB,CAAgCF,SAAS,CAAC5C,IAA1C,IACAzC,sBAAsB,CAACuF,OAAvB,CAAgCD,SAAS,CAAC7C,IAA1C,CAFD;AAIA,GALD;AAMA,QAAMc,gBAAgB,GAAG,CACxB,GAAGoB,mCADqB,EAExB,GAAGI,kBAFqB,EAGxB,GAAGF,mBAHqB,CAAzB;AAKA,SAAOtB,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"]}
|