@wordpress/edit-site 4.8.0 → 4.9.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 +2 -0
- package/build/components/add-new-template/add-custom-template-modal.js +185 -0
- package/build/components/add-new-template/add-custom-template-modal.js.map +1 -0
- package/build/components/add-new-template/new-template.js +79 -14
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/add-new-template/utils.js +139 -0
- package/build/components/add-new-template/utils.js.map +1 -0
- 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/hooks.js +1 -1
- 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-colors.js +47 -7
- package/build/components/global-styles/screen-colors.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 +40 -9
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +3 -1
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/header/index.js +28 -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/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-module/components/add-new-template/add-custom-template-modal.js +170 -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 +79 -17
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +119 -0
- package/build-module/components/add-new-template/utils.js.map +1 -0
- 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/hooks.js +1 -1
- 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-colors.js +48 -8
- package/build-module/components/global-styles/screen-colors.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 +39 -9
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +3 -1
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/header/index.js +29 -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/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-style/style-rtl.css +167 -16
- package/build-style/style.css +167 -16
- package/package.json +29 -29
- package/src/components/add-new-template/add-custom-template-modal.js +231 -0
- package/src/components/add-new-template/new-template.js +124 -47
- package/src/components/add-new-template/style.scss +116 -0
- package/src/components/add-new-template/utils.js +125 -0
- package/src/components/global-styles/context-menu.js +3 -0
- package/src/components/global-styles/hooks.js +1 -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-colors.js +49 -4
- 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 +10 -0
- package/src/components/global-styles/test/use-global-styles-output.js +82 -16
- package/src/components/global-styles/ui.js +13 -0
- package/src/components/global-styles/use-global-styles-output.js +43 -4
- package/src/components/global-styles/utils.js +3 -0
- package/src/components/header/index.js +36 -10
- package/src/components/header/more-menu/site-export.js +3 -0
- package/src/components/header/style.scss +53 -5
- 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/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
|
@@ -1,12 +1,16 @@
|
|
|
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
|
});
|
|
6
|
-
exports.default =
|
|
8
|
+
exports.default = void 0;
|
|
7
9
|
|
|
8
10
|
var _element = require("@wordpress/element");
|
|
9
11
|
|
|
12
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
+
|
|
10
14
|
var _i18n = require("@wordpress/i18n");
|
|
11
15
|
|
|
12
16
|
var _components = require("@wordpress/components");
|
|
@@ -22,12 +26,13 @@ var _coreData = require("@wordpress/core-data");
|
|
|
22
26
|
/**
|
|
23
27
|
* WordPress dependencies
|
|
24
28
|
*/
|
|
25
|
-
function UndoButton() {
|
|
29
|
+
function UndoButton(props, ref) {
|
|
26
30
|
const hasUndo = (0, _data.useSelect)(select => select(_coreData.store).hasUndo(), []);
|
|
27
31
|
const {
|
|
28
32
|
undo
|
|
29
33
|
} = (0, _data.useDispatch)(_coreData.store);
|
|
30
|
-
return (0, _element.createElement)(_components.Button, {
|
|
34
|
+
return (0, _element.createElement)(_components.Button, (0, _extends2.default)({}, props, {
|
|
35
|
+
ref: ref,
|
|
31
36
|
icon: !(0, _i18n.isRTL)() ? _icons.undo : _icons.redo,
|
|
32
37
|
label: (0, _i18n.__)('Undo'),
|
|
33
38
|
shortcut: _keycodes.displayShortcut.primary('z') // If there are no undo levels we don't want to actually disable this
|
|
@@ -36,6 +41,10 @@ function UndoButton() {
|
|
|
36
41
|
,
|
|
37
42
|
"aria-disabled": !hasUndo,
|
|
38
43
|
onClick: hasUndo ? undo : undefined
|
|
39
|
-
});
|
|
44
|
+
}));
|
|
40
45
|
}
|
|
46
|
+
|
|
47
|
+
var _default = (0, _element.forwardRef)(UndoButton);
|
|
48
|
+
|
|
49
|
+
exports.default = _default;
|
|
41
50
|
//# sourceMappingURL=undo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/header/undo-redo/undo.js"],"names":["UndoButton","hasUndo","select","coreStore","undo","undoIcon","redoIcon","displayShortcut","primary","undefined"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/header/undo-redo/undo.js"],"names":["UndoButton","props","ref","hasUndo","select","coreStore","undo","undoIcon","redoIcon","displayShortcut","primary","undefined"],"mappings":";;;;;;;;;AASA;;;;AANA;;AACA;;AACA;;AACA;;AACA;;AACA;;AARA;AACA;AACA;AASA,SAASA,UAAT,CAAqBC,KAArB,EAA4BC,GAA5B,EAAkC;AACjC,QAAMC,OAAO,GAAG,qBACbC,MAAF,IAAcA,MAAM,CAAEC,eAAF,CAAN,CAAoBF,OAApB,EADC,EAEf,EAFe,CAAhB;AAIA,QAAM;AAAEG,IAAAA;AAAF,MAAW,uBAAaD,eAAb,CAAjB;AACA,SACC,4BAAC,kBAAD,6BACMJ,KADN;AAEC,IAAA,GAAG,EAAGC,GAFP;AAGC,IAAA,IAAI,EAAG,CAAE,kBAAF,GAAYK,WAAZ,GAAuBC,WAH/B;AAIC,IAAA,KAAK,EAAG,cAAI,MAAJ,CAJT;AAKC,IAAA,QAAQ,EAAGC,0BAAgBC,OAAhB,CAAyB,GAAzB,CALZ,CAMC;AACA;AACA;AARD;AASC,qBAAgB,CAAEP,OATnB;AAUC,IAAA,OAAO,EAAGA,OAAO,GAAGG,IAAH,GAAUK;AAV5B,KADD;AAcA;;eAEc,yBAAYX,UAAZ,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, isRTL } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { undo as undoIcon, redo as redoIcon } from '@wordpress/icons';\nimport { displayShortcut } from '@wordpress/keycodes';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { forwardRef } from '@wordpress/element';\n\nfunction UndoButton( props, ref ) {\n\tconst hasUndo = useSelect(\n\t\t( select ) => select( coreStore ).hasUndo(),\n\t\t[]\n\t);\n\tconst { undo } = useDispatch( coreStore );\n\treturn (\n\t\t<Button\n\t\t\t{ ...props }\n\t\t\tref={ ref }\n\t\t\ticon={ ! isRTL() ? undoIcon : redoIcon }\n\t\t\tlabel={ __( 'Undo' ) }\n\t\t\tshortcut={ displayShortcut.primary( 'z' ) }\n\t\t\t// If there are no undo levels we don't want to actually disable this\n\t\t\t// button, because it will remove focus for keyboard users.\n\t\t\t// See: https://github.com/WordPress/gutenberg/issues/3486\n\t\t\taria-disabled={ ! hasUndo }\n\t\t\tonClick={ hasUndo ? undo : undefined }\n\t\t/>\n\t);\n}\n\nexport default forwardRef( UndoButton );\n"]}
|
|
@@ -34,12 +34,29 @@ const textFormattingShortcuts = [{
|
|
|
34
34
|
character: 'k'
|
|
35
35
|
},
|
|
36
36
|
description: (0, _i18n.__)('Remove a link.')
|
|
37
|
+
}, {
|
|
38
|
+
keyCombination: {
|
|
39
|
+
character: '[['
|
|
40
|
+
},
|
|
41
|
+
description: (0, _i18n.__)('Insert a link to a post or page')
|
|
37
42
|
}, {
|
|
38
43
|
keyCombination: {
|
|
39
44
|
modifier: 'primary',
|
|
40
45
|
character: 'u'
|
|
41
46
|
},
|
|
42
47
|
description: (0, _i18n.__)('Underline the selected text.')
|
|
48
|
+
}, {
|
|
49
|
+
keyCombination: {
|
|
50
|
+
modifier: 'access',
|
|
51
|
+
character: 'd'
|
|
52
|
+
},
|
|
53
|
+
description: (0, _i18n.__)('Strikethrough the selected text.')
|
|
54
|
+
}, {
|
|
55
|
+
keyCombination: {
|
|
56
|
+
modifier: 'access',
|
|
57
|
+
character: 'x'
|
|
58
|
+
},
|
|
59
|
+
description: (0, _i18n.__)('Make the selected text inline code.')
|
|
43
60
|
}];
|
|
44
61
|
exports.textFormattingShortcuts = textFormattingShortcuts;
|
|
45
62
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/keyboard-shortcut-help-modal/config.js"],"names":["textFormattingShortcuts","keyCombination","modifier","character","description"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;AAGO,MAAMA,uBAAuB,GAAG,CACtC;AACCC,EAAAA,cAAc,EAAE;AAAEC,IAAAA,QAAQ,EAAE,SAAZ;AAAuBC,IAAAA,SAAS,EAAE;AAAlC,GADjB;AAECC,EAAAA,WAAW,EAAE,cAAI,8BAAJ;AAFd,CADsC,EAKtC;AACCH,EAAAA,cAAc,EAAE;AAAEC,IAAAA,QAAQ,EAAE,SAAZ;AAAuBC,IAAAA,SAAS,EAAE;AAAlC,GADjB;AAECC,EAAAA,WAAW,EAAE,cAAI,gCAAJ;AAFd,CALsC,EAStC;AACCH,EAAAA,cAAc,EAAE;AAAEC,IAAAA,QAAQ,EAAE,SAAZ;AAAuBC,IAAAA,SAAS,EAAE;AAAlC,GADjB;AAECC,EAAAA,WAAW,EAAE,cAAI,wCAAJ;AAFd,CATsC,EAatC;AACCH,EAAAA,cAAc,EAAE;AAAEC,IAAAA,QAAQ,EAAE,cAAZ;AAA4BC,IAAAA,SAAS,EAAE;AAAvC,GADjB;AAECC,EAAAA,WAAW,EAAE,cAAI,gBAAJ;AAFd,CAbsC,EAiBtC;AACCH,EAAAA,cAAc,EAAE;AAAEC,IAAAA,QAAQ,EAAE,SAAZ;AAAuBC,IAAAA,SAAS,EAAE;AAAlC,GADjB;AAECC,EAAAA,WAAW,EAAE,cAAI,8BAAJ;AAFd,
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/keyboard-shortcut-help-modal/config.js"],"names":["textFormattingShortcuts","keyComb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AZ;AAAsBC,IAAAA,SAAS,EAAE;AAAjC,GADjB;AAECC,EAAAA,WAAW,EAAE,cAAI,qCAAJ;AAFd,CA7BsC,CAAhC","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\nexport const textFormattingShortcuts = [\n\t{\n\t\tkeyCombination: { modifier: 'primary', character: 'b' },\n\t\tdescription: __( 'Make the selected text bold.' ),\n\t},\n\t{\n\t\tkeyCombination: { modifier: 'primary', character: 'i' },\n\t\tdescription: __( 'Make the selected text italic.' ),\n\t},\n\t{\n\t\tkeyCombination: { modifier: 'primary', character: 'k' },\n\t\tdescription: __( 'Convert the selected text into a link.' ),\n\t},\n\t{\n\t\tkeyCombination: { modifier: 'primaryShift', character: 'k' },\n\t\tdescription: __( 'Remove a link.' ),\n\t},\n\t{\n\t\tkeyCombination: { character: '[[' },\n\t\tdescription: __( 'Insert a link to a post or page' ),\n\t},\n\t{\n\t\tkeyCombination: { modifier: 'primary', character: 'u' },\n\t\tdescription: __( 'Underline the selected text.' ),\n\t},\n\t{\n\t\tkeyCombination: { modifier: 'access', character: 'd' },\n\t\tdescription: __( 'Strikethrough the selected text.' ),\n\t},\n\t{\n\t\tkeyCombination: { modifier: 'access', character: 'x' },\n\t\tdescription: __( 'Make the selected text inline code.' ),\n\t},\n];\n"]}
|
|
@@ -19,6 +19,8 @@ var _coreData = require("@wordpress/core-data");
|
|
|
19
19
|
|
|
20
20
|
var _store = require("../../../store");
|
|
21
21
|
|
|
22
|
+
var _templateActions = _interopRequireDefault(require("./template-actions"));
|
|
23
|
+
|
|
22
24
|
var _templateAreas = _interopRequireDefault(require("./template-areas"));
|
|
23
25
|
|
|
24
26
|
/**
|
|
@@ -30,25 +32,31 @@ var _templateAreas = _interopRequireDefault(require("./template-areas"));
|
|
|
30
32
|
*/
|
|
31
33
|
function TemplateCard() {
|
|
32
34
|
const {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
info: {
|
|
36
|
+
title,
|
|
37
|
+
description,
|
|
38
|
+
icon
|
|
39
|
+
},
|
|
40
|
+
template
|
|
36
41
|
} = (0, _data.useSelect)(select => {
|
|
37
42
|
const {
|
|
38
43
|
getEditedPostType,
|
|
39
44
|
getEditedPostId
|
|
40
45
|
} = select(_store.store);
|
|
41
46
|
const {
|
|
42
|
-
|
|
47
|
+
getEditedEntityRecord
|
|
43
48
|
} = select(_coreData.store);
|
|
44
49
|
const {
|
|
45
50
|
__experimentalGetTemplateInfo: getTemplateInfo
|
|
46
51
|
} = select(_editor.store);
|
|
47
52
|
const postType = getEditedPostType();
|
|
48
53
|
const postId = getEditedPostId();
|
|
49
|
-
const record =
|
|
54
|
+
const record = getEditedEntityRecord('postType', postType, postId);
|
|
50
55
|
const info = record ? getTemplateInfo(record) : {};
|
|
51
|
-
return
|
|
56
|
+
return {
|
|
57
|
+
info,
|
|
58
|
+
template: record
|
|
59
|
+
};
|
|
52
60
|
}, []);
|
|
53
61
|
|
|
54
62
|
if (!title && !description) {
|
|
@@ -62,9 +70,13 @@ function TemplateCard() {
|
|
|
62
70
|
icon: icon
|
|
63
71
|
}), (0, _element.createElement)("div", {
|
|
64
72
|
className: "edit-site-template-card__content"
|
|
73
|
+
}, (0, _element.createElement)("div", {
|
|
74
|
+
className: "edit-site-template-card__header"
|
|
65
75
|
}, (0, _element.createElement)("h2", {
|
|
66
76
|
className: "edit-site-template-card__title"
|
|
67
|
-
}, title), (0, _element.createElement)(
|
|
77
|
+
}, title), (0, _element.createElement)(_templateActions.default, {
|
|
78
|
+
template: template
|
|
79
|
+
})), (0, _element.createElement)("div", {
|
|
68
80
|
className: "edit-site-template-card__description"
|
|
69
81
|
}, description), (0, _element.createElement)(_templateAreas.default, null)));
|
|
70
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/sidebar/template-card/index.js"],"names":["TemplateCard","title","description","icon","select","getEditedPostType","getEditedPostId","editSiteStore","
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/sidebar/template-card/index.js"],"names":["TemplateCard","info","title","description","icon","template","select","getEditedPostType","getEditedPostId","editSiteStore","getEditedEntityRecord","coreStore","__experimentalGetTemplateInfo","getTemplateInfo","editorStore","postType","postId","record"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AAbA;AACA;AACA;;AAMA;AACA;AACA;AAKe,SAASA,YAAT,GAAwB;AACtC,QAAM;AACLC,IAAAA,IAAI,EAAE;AAAEC,MAAAA,KAAF;AAASC,MAAAA,WAAT;AAAsBC,MAAAA;AAAtB,KADD;AAELC,IAAAA;AAFK,MAGF,qBAAaC,MAAF,IAAc;AAC5B,UAAM;AAAEC,MAAAA,iBAAF;AAAqBC,MAAAA;AAArB,QAAyCF,MAAM,CAAEG,YAAF,CAArD;AACA,UAAM;AAAEC,MAAAA;AAAF,QAA4BJ,MAAM,CAAEK,eAAF,CAAxC;AACA,UAAM;AAAEC,MAAAA,6BAA6B,EAAEC;AAAjC,QACLP,MAAM,CAAEQ,aAAF,CADP;AAGA,UAAMC,QAAQ,GAAGR,iBAAiB,EAAlC;AACA,UAAMS,MAAM,GAAGR,eAAe,EAA9B;AACA,UAAMS,MAAM,GAAGP,qBAAqB,CAAE,UAAF,EAAcK,QAAd,EAAwBC,MAAxB,CAApC;AAEA,UAAMf,IAAI,GAAGgB,MAAM,GAAGJ,eAAe,CAAEI,MAAF,CAAlB,GAA+B,EAAlD;AAEA,WAAO;AAAEhB,MAAAA,IAAF;AAAQI,MAAAA,QAAQ,EAAEY;AAAlB,KAAP;AACA,GAbG,EAaD,EAbC,CAHJ;;AAkBA,MAAK,CAAEf,KAAF,IAAW,CAAEC,WAAlB,EAAgC;AAC/B,WAAO,IAAP;AACA;;AAED,SACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,4BAAC,gBAAD;AAAM,IAAA,SAAS,EAAC,+BAAhB;AAAgD,IAAA,IAAI,EAAGC;AAAvD,IADD,EAEC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC;AAAI,IAAA,SAAS,EAAC;AAAd,KACGF,KADH,CADD,EAIC,4BAAC,wBAAD;AAAiB,IAAA,QAAQ,EAAGG;AAA5B,IAJD,CADD,EAOC;AAAK,IAAA,SAAS,EAAC;AAAf,KACGF,WADH,CAPD,EAUC,4BAAC,sBAAD,OAVD,CAFD,CADD;AAiBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { Icon } from '@wordpress/components';\nimport { store as editorStore } from '@wordpress/editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../../store';\nimport TemplateActions from './template-actions';\nimport TemplateAreas from './template-areas';\n\nexport default function TemplateCard() {\n\tconst {\n\t\tinfo: { title, description, icon },\n\t\ttemplate,\n\t} = useSelect( ( select ) => {\n\t\tconst { getEditedPostType, getEditedPostId } = select( editSiteStore );\n\t\tconst { getEditedEntityRecord } = select( coreStore );\n\t\tconst { __experimentalGetTemplateInfo: getTemplateInfo } =\n\t\t\tselect( editorStore );\n\n\t\tconst postType = getEditedPostType();\n\t\tconst postId = getEditedPostId();\n\t\tconst record = getEditedEntityRecord( 'postType', postType, postId );\n\n\t\tconst info = record ? getTemplateInfo( record ) : {};\n\n\t\treturn { info, template: record };\n\t}, [] );\n\n\tif ( ! title && ! description ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<div className=\"edit-site-template-card\">\n\t\t\t<Icon className=\"edit-site-template-card__icon\" icon={ icon } />\n\t\t\t<div className=\"edit-site-template-card__content\">\n\t\t\t\t<div className=\"edit-site-template-card__header\">\n\t\t\t\t\t<h2 className=\"edit-site-template-card__title\">\n\t\t\t\t\t\t{ title }\n\t\t\t\t\t</h2>\n\t\t\t\t\t<TemplateActions template={ template } />\n\t\t\t\t</div>\n\t\t\t\t<div className=\"edit-site-template-card__description\">\n\t\t\t\t\t{ description }\n\t\t\t\t</div>\n\t\t\t\t<TemplateAreas />\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
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 = Actions;
|
|
9
|
+
|
|
10
|
+
var _element = require("@wordpress/element");
|
|
11
|
+
|
|
12
|
+
var _data = require("@wordpress/data");
|
|
13
|
+
|
|
14
|
+
var _i18n = require("@wordpress/i18n");
|
|
15
|
+
|
|
16
|
+
var _components = require("@wordpress/components");
|
|
17
|
+
|
|
18
|
+
var _icons = require("@wordpress/icons");
|
|
19
|
+
|
|
20
|
+
var _store = require("../../../store");
|
|
21
|
+
|
|
22
|
+
var _isTemplateRevertable = _interopRequireDefault(require("../../../utils/is-template-revertable"));
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* WordPress dependencies
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Internal dependencies
|
|
30
|
+
*/
|
|
31
|
+
function Actions(_ref) {
|
|
32
|
+
let {
|
|
33
|
+
template
|
|
34
|
+
} = _ref;
|
|
35
|
+
const {
|
|
36
|
+
revertTemplate
|
|
37
|
+
} = (0, _data.useDispatch)(_store.store);
|
|
38
|
+
const isRevertable = (0, _isTemplateRevertable.default)(template);
|
|
39
|
+
|
|
40
|
+
if (!isRevertable) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return (0, _element.createElement)(_components.DropdownMenu, {
|
|
45
|
+
icon: _icons.moreVertical,
|
|
46
|
+
label: (0, _i18n.__)('Actions'),
|
|
47
|
+
className: "edit-site-template-card__actions",
|
|
48
|
+
toggleProps: {
|
|
49
|
+
isSmall: true
|
|
50
|
+
}
|
|
51
|
+
}, _ref2 => {
|
|
52
|
+
let {
|
|
53
|
+
onClose
|
|
54
|
+
} = _ref2;
|
|
55
|
+
return (0, _element.createElement)(_components.MenuGroup, null, (0, _element.createElement)(_components.MenuItem, {
|
|
56
|
+
info: (0, _i18n.__)('Restore to default state'),
|
|
57
|
+
onClick: () => {
|
|
58
|
+
revertTemplate(template);
|
|
59
|
+
onClose();
|
|
60
|
+
}
|
|
61
|
+
}, (0, _i18n.__)('Clear customizations')));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=template-actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/sidebar/template-card/template-actions.js"],"names":["Actions","template","revertTemplate","editSiteStore","isRevertable","moreVertical","isSmall","onClose"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAZA;AACA;AACA;;AAMA;AACA;AACA;AAIe,SAASA,OAAT,OAAiC;AAAA,MAAf;AAAEC,IAAAA;AAAF,GAAe;AAC/C,QAAM;AAAEC,IAAAA;AAAF,MAAqB,uBAAaC,YAAb,CAA3B;AACA,QAAMC,YAAY,GAAG,mCAAsBH,QAAtB,CAArB;;AACA,MAAK,CAAEG,YAAP,EAAsB;AACrB,WAAO,IAAP;AACA;;AACD,SACC,4BAAC,wBAAD;AACC,IAAA,IAAI,EAAGC,mBADR;AAEC,IAAA,KAAK,EAAG,cAAI,SAAJ,CAFT;AAGC,IAAA,SAAS,EAAC,kCAHX;AAIC,IAAA,WAAW,EAAG;AAAEC,MAAAA,OAAO,EAAE;AAAX;AAJf,KAMG;AAAA,QAAE;AAAEC,MAAAA;AAAF,KAAF;AAAA,WACD,4BAAC,qBAAD,QACC,4BAAC,oBAAD;AACC,MAAA,IAAI,EAAG,cAAI,0BAAJ,CADR;AAEC,MAAA,OAAO,EAAG,MAAM;AACfL,QAAAA,cAAc,CAAED,QAAF,CAAd;AACAM,QAAAA,OAAO;AACP;AALF,OAOG,cAAI,sBAAJ,CAPH,CADD,CADC;AAAA,GANH,CADD;AAsBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';\nimport { moreVertical } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../../store';\nimport isTemplateRevertable from '../../../utils/is-template-revertable';\n\nexport default function Actions( { template } ) {\n\tconst { revertTemplate } = useDispatch( editSiteStore );\n\tconst isRevertable = isTemplateRevertable( template );\n\tif ( ! isRevertable ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<DropdownMenu\n\t\t\ticon={ moreVertical }\n\t\t\tlabel={ __( 'Actions' ) }\n\t\t\tclassName=\"edit-site-template-card__actions\"\n\t\t\ttoggleProps={ { isSmall: true } }\n\t\t>\n\t\t\t{ ( { onClose } ) => (\n\t\t\t\t<MenuGroup>\n\t\t\t\t\t<MenuItem\n\t\t\t\t\t\tinfo={ __( 'Restore to default state' ) }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\trevertTemplate( template );\n\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Clear customizations' ) }\n\t\t\t\t\t</MenuItem>\n\t\t\t\t</MenuGroup>\n\t\t\t) }\n\t\t</DropdownMenu>\n\t);\n}\n"]}
|
|
@@ -0,0 +1,170 @@
|
|
|
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, __experimentalHeading as Heading, __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
|
+
const BASE_QUERY = {
|
|
19
|
+
order: 'asc',
|
|
20
|
+
_fields: 'id,title,slug,link',
|
|
21
|
+
context: 'view'
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function SuggestionListItem(_ref) {
|
|
25
|
+
let {
|
|
26
|
+
suggestion,
|
|
27
|
+
search,
|
|
28
|
+
onSelect,
|
|
29
|
+
entityForSuggestions,
|
|
30
|
+
composite
|
|
31
|
+
} = _ref;
|
|
32
|
+
const baseCssClass = 'edit-site-custom-template-modal__suggestions_list__list-item';
|
|
33
|
+
return createElement(CompositeItem, _extends({
|
|
34
|
+
role: "option",
|
|
35
|
+
as: Button
|
|
36
|
+
}, composite, {
|
|
37
|
+
className: baseCssClass,
|
|
38
|
+
onClick: () => {
|
|
39
|
+
const title = sprintf( // translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the singular name of a post type and %2$s is the name of the post, e.g. "Post: Hello, WordPress"
|
|
40
|
+
__('%1$s: %2$s'), entityForSuggestions.labels.singular_name, suggestion.name);
|
|
41
|
+
onSelect({
|
|
42
|
+
title,
|
|
43
|
+
description: sprintf( // translators: Represents the description of a user's custom template in the Site Editor, e.g. "Template for Post: Hello, WordPress"
|
|
44
|
+
__('Template for %1$s'), title),
|
|
45
|
+
slug: `single-${entityForSuggestions.slug}-${suggestion.slug}`
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}), createElement("span", {
|
|
49
|
+
className: `${baseCssClass}__title`
|
|
50
|
+
}, createElement(TextHighlight, {
|
|
51
|
+
text: suggestion.name,
|
|
52
|
+
highlight: search
|
|
53
|
+
})), suggestion.link && createElement("span", {
|
|
54
|
+
className: `${baseCssClass}__info`
|
|
55
|
+
}, suggestion.link));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function SuggestionList(_ref2) {
|
|
59
|
+
let {
|
|
60
|
+
entityForSuggestions,
|
|
61
|
+
onSelect
|
|
62
|
+
} = _ref2;
|
|
63
|
+
const composite = useCompositeState({
|
|
64
|
+
orientation: 'vertical'
|
|
65
|
+
});
|
|
66
|
+
const [suggestions, setSuggestions] = useState(EMPTY_ARRAY); // We need to track two values, the search input's value(searchInputValue)
|
|
67
|
+
// and the one we want to debounce(search) and make REST API requests.
|
|
68
|
+
|
|
69
|
+
const [searchInputValue, setSearchInputValue] = useState('');
|
|
70
|
+
const [search, setSearch] = useState('');
|
|
71
|
+
const debouncedSearch = useDebounce(setSearch, 250);
|
|
72
|
+
const query = { ...BASE_QUERY,
|
|
73
|
+
search,
|
|
74
|
+
orderby: search ? 'relevance' : 'modified',
|
|
75
|
+
exclude: entityForSuggestions.postsToExclude,
|
|
76
|
+
per_page: search ? 20 : 10
|
|
77
|
+
};
|
|
78
|
+
const {
|
|
79
|
+
records: searchResults,
|
|
80
|
+
hasResolved: searchHasResolved
|
|
81
|
+
} = useEntityRecords(entityForSuggestions.type, entityForSuggestions.slug, query);
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (search !== searchInputValue) {
|
|
84
|
+
debouncedSearch(searchInputValue);
|
|
85
|
+
}
|
|
86
|
+
}, [search, searchInputValue]);
|
|
87
|
+
const entitiesInfo = useMemo(() => {
|
|
88
|
+
if (!(searchResults !== null && searchResults !== void 0 && searchResults.length)) return EMPTY_ARRAY;
|
|
89
|
+
return mapToIHasNameAndId(searchResults, 'title.rendered');
|
|
90
|
+
}, [searchResults]); // Update suggestions only when the query has resolved.
|
|
91
|
+
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (!searchHasResolved) return;
|
|
94
|
+
setSuggestions(entitiesInfo);
|
|
95
|
+
}, [entitiesInfo, searchHasResolved]);
|
|
96
|
+
return createElement(Fragment, null, createElement(SearchControl, {
|
|
97
|
+
onChange: setSearchInputValue,
|
|
98
|
+
value: searchInputValue,
|
|
99
|
+
label: entityForSuggestions.labels.search_items,
|
|
100
|
+
placeholder: entityForSuggestions.labels.search_items
|
|
101
|
+
}), !!(suggestions !== null && suggestions !== void 0 && suggestions.length) && createElement(Composite, _extends({}, composite, {
|
|
102
|
+
role: "listbox",
|
|
103
|
+
className: "edit-site-custom-template-modal__suggestions_list"
|
|
104
|
+
}), suggestions.map(suggestion => createElement(SuggestionListItem, {
|
|
105
|
+
key: suggestion.slug,
|
|
106
|
+
suggestion: suggestion,
|
|
107
|
+
search: search,
|
|
108
|
+
onSelect: onSelect,
|
|
109
|
+
entityForSuggestions: entityForSuggestions,
|
|
110
|
+
composite: composite
|
|
111
|
+
}))), search && !(suggestions !== null && suggestions !== void 0 && suggestions.length) && createElement("p", {
|
|
112
|
+
className: "edit-site-custom-template-modal__no-results"
|
|
113
|
+
}, entityForSuggestions.labels.not_found));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function AddCustomTemplateModal(_ref3) {
|
|
117
|
+
let {
|
|
118
|
+
onClose,
|
|
119
|
+
onSelect,
|
|
120
|
+
entityForSuggestions
|
|
121
|
+
} = _ref3;
|
|
122
|
+
const [showSearchEntities, setShowSearchEntities] = useState(entityForSuggestions.hasGeneralTemplate);
|
|
123
|
+
const baseCssClass = 'edit-site-custom-template-modal';
|
|
124
|
+
return createElement(Modal, {
|
|
125
|
+
title: sprintf( // translators: %s: Name of the post type e.g: "Post".
|
|
126
|
+
__('Add template: %s'), entityForSuggestions.labels.singular_name),
|
|
127
|
+
className: baseCssClass,
|
|
128
|
+
closeLabel: __('Close'),
|
|
129
|
+
onRequestClose: onClose
|
|
130
|
+
}, !showSearchEntities && createElement(Fragment, null, createElement("p", null, __('Select whether to create a single template for all items or a specific one.')), createElement(Flex, {
|
|
131
|
+
className: `${baseCssClass}__contents`,
|
|
132
|
+
gap: "4",
|
|
133
|
+
align: "initial"
|
|
134
|
+
}, createElement(FlexItem, {
|
|
135
|
+
isBlock: true,
|
|
136
|
+
onClick: () => {
|
|
137
|
+
const {
|
|
138
|
+
slug,
|
|
139
|
+
title,
|
|
140
|
+
description
|
|
141
|
+
} = entityForSuggestions.template;
|
|
142
|
+
onSelect({
|
|
143
|
+
slug,
|
|
144
|
+
title,
|
|
145
|
+
description
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}, createElement(Heading, {
|
|
149
|
+
level: 5
|
|
150
|
+
}, entityForSuggestions.labels.all_items), createElement(Text, {
|
|
151
|
+
as: "span"
|
|
152
|
+
}, // translators: The user is given the choice to set up a template for all items of a post type, or just a specific one.
|
|
153
|
+
__('For all items'))), createElement(FlexItem, {
|
|
154
|
+
isBlock: true,
|
|
155
|
+
onClick: () => {
|
|
156
|
+
setShowSearchEntities(true);
|
|
157
|
+
}
|
|
158
|
+
}, createElement(Heading, {
|
|
159
|
+
level: 5
|
|
160
|
+
}, entityForSuggestions.labels.singular_name), createElement(Text, {
|
|
161
|
+
as: "span"
|
|
162
|
+
}, // translators: The user is given the choice to set up a template for all items of a post type, or just a specific one.
|
|
163
|
+
__('For a specific item'))))), showSearchEntities && createElement(Fragment, null, createElement("p", null, __('This template will be used only for the specific item chosen.')), createElement(SuggestionList, {
|
|
164
|
+
entityForSuggestions: entityForSuggestions,
|
|
165
|
+
onSelect: onSelect
|
|
166
|
+
})));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export default AddCustomTemplateModal;
|
|
170
|
+
//# 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","__experimentalHeading","Heading","__unstableComposite","Composite","__unstableUseCompositeState","useCompositeState","__unstableCompositeItem","CompositeItem","useDebounce","useEntityRecords","mapToIHasNameAndId","EMPTY_ARRAY","BASE_QUERY","order","_fields","context","SuggestionListItem","suggestion","search","onSelect","entityForSuggestions","composite","baseCssClass","title","labels","singular_name","name","description","slug","link","SuggestionList","orientation","suggestions","setSuggestions","searchInputValue","setSearchInputValue","setSearch","debouncedSearch","query","orderby","exclude","postsToExclude","per_page","records","searchResults","hasResolved","searchHasResolved","type","entitiesInfo","length","search_items","map","not_found","AddCustomTemplateModal","onClose","showSearchEntities","setShowSearchEntities","hasGeneralTemplate","template","all_items"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,OAAnB,EAA4BC,SAA5B,QAA6C,oBAA7C;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SACCC,MADD,EAECC,IAFD,EAGCC,QAHD,EAICC,KAJD,EAKCC,aALD,EAMCC,aAND,EAOCC,kBAAkB,IAAIC,IAPvB,EAQCC,qBAAqB,IAAIC,OAR1B,EASCC,mBAAmB,IAAIC,SATxB,EAUCC,2BAA2B,IAAIC,iBAVhC,EAWCC,uBAAuB,IAAIC,aAX5B,QAYO,uBAZP;AAaA,SAASC,WAAT,QAA4B,oBAA5B;AACA,SAASC,gBAAT,QAAiC,sBAAjC;AAEA;AACA;AACA;;AACA,SAASC,kBAAT,QAAmC,SAAnC;AAEA,MAAMC,WAAW,GAAG,EAApB;AACA,MAAMC,UAAU,GAAG;AAClBC,EAAAA,KAAK,EAAE,KADW;AAElBC,EAAAA,OAAO,EAAE,oBAFS;AAGlBC,EAAAA,OAAO,EAAE;AAHS,CAAnB;;AAMA,SAASC,kBAAT,OAMI;AAAA,MANyB;AAC5BC,IAAAA,UAD4B;AAE5BC,IAAAA,MAF4B;AAG5BC,IAAAA,QAH4B;AAI5BC,IAAAA,oBAJ4B;A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AQ,EAAGD;AAFZ,IAND,CA5DF,CADD;AA2EA;;AAED,eAAekC,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__experimentalHeading as Heading,\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 = [];\nconst BASE_QUERY = {\n\torder: 'asc',\n\t_fields: 'id,title,slug,link',\n\tcontext: 'view',\n};\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\tconst title = sprintf(\n\t\t\t\t\t// translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the singular name of a post type and %2$s is the name of the post, e.g. \"Post: Hello, WordPress\"\n\t\t\t\t\t__( '%1$s: %2$s' ),\n\t\t\t\t\tentityForSuggestions.labels.singular_name,\n\t\t\t\t\tsuggestion.name\n\t\t\t\t);\n\t\t\t\tonSelect( {\n\t\t\t\t\ttitle,\n\t\t\t\t\tdescription: sprintf(\n\t\t\t\t\t\t// translators: Represents the description of a user's custom template in the Site Editor, e.g. \"Template for Post: Hello, WordPress\"\n\t\t\t\t\t\t__( 'Template for %1$s' ),\n\t\t\t\t\t\ttitle\n\t\t\t\t\t),\n\t\t\t\t\tslug: `single-${ entityForSuggestions.slug }-${ suggestion.slug }`,\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 SuggestionList( { entityForSuggestions, onSelect } ) {\n\tconst composite = useCompositeState( { orientation: 'vertical' } );\n\tconst [ suggestions, setSuggestions ] = useState( EMPTY_ARRAY );\n\t// We need to track two values, the search input's value(searchInputValue)\n\t// and the one we want to debounce(search) and make REST API requests.\n\tconst [ searchInputValue, setSearchInputValue ] = useState( '' );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst debouncedSearch = useDebounce( setSearch, 250 );\n\tconst query = {\n\t\t...BASE_QUERY,\n\t\tsearch,\n\t\torderby: search ? 'relevance' : 'modified',\n\t\texclude: entityForSuggestions.postsToExclude,\n\t\tper_page: search ? 20 : 10,\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\tuseEffect( () => {\n\t\tif ( search !== searchInputValue ) {\n\t\t\tdebouncedSearch( searchInputValue );\n\t\t}\n\t}, [ search, searchInputValue ] );\n\tconst entitiesInfo = useMemo( () => {\n\t\tif ( ! searchResults?.length ) return EMPTY_ARRAY;\n\t\treturn mapToIHasNameAndId( searchResults, 'title.rendered' );\n\t}, [ searchResults ] );\n\t// Update suggestions only when the query has resolved.\n\tuseEffect( () => {\n\t\tif ( ! searchHasResolved ) return;\n\t\tsetSuggestions( entitiesInfo );\n\t}, [ entitiesInfo, searchHasResolved ] );\n\treturn (\n\t\t<>\n\t\t\t<SearchControl\n\t\t\t\tonChange={ setSearchInputValue }\n\t\t\t\tvalue={ searchInputValue }\n\t\t\t\tlabel={ entityForSuggestions.labels.search_items }\n\t\t\t\tplaceholder={ entityForSuggestions.labels.search_items }\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>\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={ search }\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{ search && ! suggestions?.length && (\n\t\t\t\t<p className=\"edit-site-custom-template-modal__no-results\">\n\t\t\t\t\t{ entityForSuggestions.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\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<Heading level={ 5 }>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.all_items }\n\t\t\t\t\t\t\t</Heading>\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 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\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<Heading level={ 5 }>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.singular_name }\n\t\t\t\t\t\t\t</Heading>\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 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,27 @@
|
|
|
1
|
-
import { createElement } from "@wordpress/element";
|
|
1
|
+
import { createElement, Fragment } from "@wordpress/element";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* External dependencies
|
|
5
5
|
*/
|
|
6
|
-
import { filter, includes
|
|
6
|
+
import { filter, includes } from 'lodash';
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { DropdownMenu, MenuGroup, MenuItem, NavigableMenu } from '@wordpress/components';
|
|
12
|
+
import { useState } from '@wordpress/element';
|
|
12
13
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
13
14
|
import { store as coreStore } from '@wordpress/core-data';
|
|
14
15
|
import { store as editorStore } from '@wordpress/editor';
|
|
15
16
|
import { archive, blockMeta, category, home, list, media, notFound, page, post, postAuthor, postDate, search, tag } from '@wordpress/icons';
|
|
16
|
-
import { __ } from '@wordpress/i18n';
|
|
17
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
17
18
|
import { store as noticesStore } from '@wordpress/notices';
|
|
18
19
|
/**
|
|
19
20
|
* Internal dependencies
|
|
20
21
|
*/
|
|
21
22
|
|
|
23
|
+
import AddCustomTemplateModal from './add-custom-template-modal';
|
|
24
|
+
import { usePostTypes, usePostTypesEntitiesInfo } from './utils';
|
|
22
25
|
import { useHistory } from '../routes';
|
|
23
26
|
import { store as editSiteStore } from '../../store';
|
|
24
27
|
const DEFAULT_TEMPLATE_SLUGS = ['front-page', 'single', 'page', 'index', 'archive', 'author', 'category', 'date', 'tag', 'taxonomy', 'search', '404'];
|
|
@@ -42,15 +45,19 @@ export default function NewTemplate(_ref) {
|
|
|
42
45
|
postType
|
|
43
46
|
} = _ref;
|
|
44
47
|
const history = useHistory();
|
|
48
|
+
const postTypes = usePostTypes();
|
|
49
|
+
const [showCustomTemplateModal, setShowCustomTemplateModal] = useState(false);
|
|
50
|
+
const [entityForSuggestions, setEntityForSuggestions] = useState({});
|
|
45
51
|
const {
|
|
46
|
-
|
|
52
|
+
existingTemplates,
|
|
47
53
|
defaultTemplateTypes
|
|
48
54
|
} = useSelect(select => ({
|
|
49
|
-
|
|
55
|
+
existingTemplates: select(coreStore).getEntityRecords('postType', 'wp_template', {
|
|
50
56
|
per_page: -1
|
|
51
57
|
}),
|
|
52
58
|
defaultTemplateTypes: select(editorStore).__experimentalGetDefaultTemplateTypes()
|
|
53
59
|
}), []);
|
|
60
|
+
const postTypesEntitiesInfo = usePostTypesEntitiesInfo(existingTemplates);
|
|
54
61
|
const {
|
|
55
62
|
saveEntityRecord
|
|
56
63
|
} = useDispatch(coreStore);
|
|
@@ -94,18 +101,69 @@ export default function NewTemplate(_ref) {
|
|
|
94
101
|
}
|
|
95
102
|
}
|
|
96
103
|
|
|
97
|
-
const existingTemplateSlugs = map(
|
|
104
|
+
const existingTemplateSlugs = (existingTemplates || []).map(_ref2 => {
|
|
105
|
+
let {
|
|
106
|
+
slug
|
|
107
|
+
} = _ref2;
|
|
108
|
+
return slug;
|
|
109
|
+
});
|
|
98
110
|
const missingTemplates = filter(defaultTemplateTypes, template => includes(DEFAULT_TEMPLATE_SLUGS, template.slug) && !includes(existingTemplateSlugs, template.slug));
|
|
111
|
+
const extraTemplates = (postTypes || []).reduce((accumulator, _postType) => {
|
|
112
|
+
var _postTypesEntitiesInf;
|
|
113
|
+
|
|
114
|
+
const {
|
|
115
|
+
slug,
|
|
116
|
+
labels,
|
|
117
|
+
icon
|
|
118
|
+
} = _postType;
|
|
119
|
+
const hasGeneralTemplate = existingTemplateSlugs === null || existingTemplateSlugs === void 0 ? void 0 : existingTemplateSlugs.includes(`single-${slug}`);
|
|
120
|
+
const hasEntities = postTypesEntitiesInfo === null || postTypesEntitiesInfo === void 0 ? void 0 : (_postTypesEntitiesInf = postTypesEntitiesInfo[slug]) === null || _postTypesEntitiesInf === void 0 ? void 0 : _postTypesEntitiesInf.hasEntities;
|
|
121
|
+
const menuItem = {
|
|
122
|
+
slug: `single-${slug}`,
|
|
123
|
+
title: sprintf( // translators: %s: Name of the post type e.g: "Post".
|
|
124
|
+
__('Single item: %s'), labels.singular_name),
|
|
125
|
+
description: sprintf( // translators: %s: Name of the post type e.g: "Post".
|
|
126
|
+
__('Displays a single item: %s.'), labels.singular_name),
|
|
127
|
+
// `icon` is the `menu_icon` property of a post type. We
|
|
128
|
+
// only handle `dashicons` for now, even if the `menu_icon`
|
|
129
|
+
// also supports urls and svg as values.
|
|
130
|
+
icon: icon !== null && icon !== void 0 && icon.startsWith('dashicons-') ? icon.slice(10) : null
|
|
131
|
+
}; // We have a different template creation flow only if they have entities.
|
|
132
|
+
|
|
133
|
+
if (hasEntities) {
|
|
134
|
+
menuItem.onClick = template => {
|
|
135
|
+
setShowCustomTemplateModal(true);
|
|
136
|
+
setEntityForSuggestions({
|
|
137
|
+
type: 'postType',
|
|
138
|
+
slug,
|
|
139
|
+
labels,
|
|
140
|
+
hasGeneralTemplate,
|
|
141
|
+
template,
|
|
142
|
+
postsToExclude: postTypesEntitiesInfo[slug].existingPosts
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
} // We don't need to add the menu item if there are no
|
|
146
|
+
// entities and the general template exists.
|
|
147
|
+
|
|
99
148
|
|
|
100
|
-
|
|
149
|
+
if (!hasGeneralTemplate || hasEntities) {
|
|
150
|
+
accumulator.push(menuItem);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return accumulator;
|
|
154
|
+
}, []);
|
|
155
|
+
|
|
156
|
+
if (!missingTemplates.length && !extraTemplates.length) {
|
|
101
157
|
return null;
|
|
102
158
|
} // Update the sort order to match the DEFAULT_TEMPLATE_SLUGS order.
|
|
103
159
|
|
|
104
160
|
|
|
105
|
-
missingTemplates.sort((template1, template2) => {
|
|
161
|
+
missingTemplates === null || missingTemplates === void 0 ? void 0 : missingTemplates.sort((template1, template2) => {
|
|
106
162
|
return DEFAULT_TEMPLATE_SLUGS.indexOf(template1.slug) - DEFAULT_TEMPLATE_SLUGS.indexOf(template2.slug);
|
|
107
|
-
});
|
|
108
|
-
|
|
163
|
+
}); // Append all extra templates at the end of the list for now.
|
|
164
|
+
|
|
165
|
+
missingTemplates.push(...extraTemplates);
|
|
166
|
+
return createElement(Fragment, null, createElement(DropdownMenu, {
|
|
109
167
|
className: "edit-site-new-template-dropdown",
|
|
110
168
|
icon: null,
|
|
111
169
|
text: postType.labels.add_new,
|
|
@@ -120,21 +178,25 @@ export default function NewTemplate(_ref) {
|
|
|
120
178
|
className: "edit-site-new-template-dropdown__popover"
|
|
121
179
|
}, createElement(MenuGroup, {
|
|
122
180
|
label: postType.labels.add_new_item
|
|
123
|
-
}, map(
|
|
181
|
+
}, missingTemplates.map(template => {
|
|
124
182
|
const {
|
|
125
183
|
title,
|
|
126
184
|
description,
|
|
127
|
-
slug
|
|
185
|
+
slug,
|
|
186
|
+
onClick,
|
|
187
|
+
icon
|
|
128
188
|
} = template;
|
|
129
189
|
return createElement(MenuItem, {
|
|
130
|
-
icon: TEMPLATE_ICONS[slug],
|
|
190
|
+
icon: icon || TEMPLATE_ICONS[slug] || post,
|
|
131
191
|
iconPosition: "left",
|
|
132
192
|
info: description,
|
|
133
193
|
key: slug,
|
|
134
|
-
onClick: () =>
|
|
135
|
-
createTemplate(template); // We will be navigated way so no need to close the dropdown.
|
|
136
|
-
}
|
|
194
|
+
onClick: () => onClick ? onClick(template) : createTemplate(template)
|
|
137
195
|
}, title);
|
|
138
|
-
}))))
|
|
196
|
+
})))), showCustomTemplateModal && createElement(AddCustomTemplateModal, {
|
|
197
|
+
onClose: () => setShowCustomTemplateModal(false),
|
|
198
|
+
onSelect: createTemplate,
|
|
199
|
+
entityForSuggestions: entityForSuggestions
|
|
200
|
+
}));
|
|
139
201
|
}
|
|
140
202
|
//# sourceMappingURL=new-template.js.map
|