@wordpress/edit-post 7.24.0 → 7.25.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/header/header-toolbar/index.js +8 -4
- package/build/components/header/header-toolbar/index.js.map +1 -1
- package/build/components/header/index.js +13 -11
- package/build/components/header/index.js.map +1 -1
- package/build/components/header/mode-switcher/index.js +1 -1
- package/build/components/header/mode-switcher/index.js.map +1 -1
- package/build/components/header/more-menu/index.js +2 -1
- package/build/components/header/more-menu/index.js.map +1 -1
- package/build/components/header/writing-menu/index.js +13 -12
- package/build/components/header/writing-menu/index.js.map +1 -1
- package/build/components/layout/index.js +12 -12
- package/build/components/layout/index.js.map +1 -1
- package/build/components/preferences-modal/index.js +65 -49
- package/build/components/preferences-modal/index.js.map +1 -1
- package/build/components/sidebar/post-status/index.js +1 -2
- package/build/components/sidebar/post-status/index.js.map +1 -1
- package/build/components/sidebar/settings-header/index.js +17 -43
- package/build/components/sidebar/settings-header/index.js.map +1 -1
- package/build/components/sidebar/settings-sidebar/index.js +80 -20
- package/build/components/sidebar/settings-sidebar/index.js.map +1 -1
- package/build/components/start-page-options/index.js +3 -3
- package/build/components/start-page-options/index.js.map +1 -1
- package/build/components/visual-editor/index.js +20 -257
- package/build/components/visual-editor/index.js.map +1 -1
- package/build/components/welcome-guide/index.js +6 -3
- package/build/components/welcome-guide/index.js.map +1 -1
- package/build/editor.js +5 -6
- package/build/editor.js.map +1 -1
- package/build/editor.native.js +1 -2
- package/build/editor.native.js.map +1 -1
- package/build/index.js +5 -4
- package/build/index.js.map +1 -1
- package/build/plugins/welcome-guide-menu-item/index.js +2 -6
- package/build/plugins/welcome-guide-menu-item/index.js.map +1 -1
- package/build/store/actions.js +35 -39
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +1 -34
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +22 -12
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/header/header-toolbar/index.js +8 -4
- package/build-module/components/header/header-toolbar/index.js.map +1 -1
- package/build-module/components/header/index.js +15 -13
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/header/mode-switcher/index.js +1 -1
- package/build-module/components/header/mode-switcher/index.js.map +1 -1
- package/build-module/components/header/more-menu/index.js +2 -1
- package/build-module/components/header/more-menu/index.js.map +1 -1
- package/build-module/components/header/writing-menu/index.js +14 -13
- package/build-module/components/header/writing-menu/index.js.map +1 -1
- package/build-module/components/layout/index.js +13 -13
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/preferences-modal/index.js +65 -49
- package/build-module/components/preferences-modal/index.js.map +1 -1
- package/build-module/components/sidebar/post-status/index.js +2 -3
- package/build-module/components/sidebar/post-status/index.js.map +1 -1
- package/build-module/components/sidebar/settings-header/index.js +20 -46
- package/build-module/components/sidebar/settings-header/index.js.map +1 -1
- package/build-module/components/sidebar/settings-sidebar/index.js +80 -21
- package/build-module/components/sidebar/settings-sidebar/index.js.map +1 -1
- package/build-module/components/start-page-options/index.js +3 -3
- package/build-module/components/start-page-options/index.js.map +1 -1
- package/build-module/components/visual-editor/index.js +24 -261
- package/build-module/components/visual-editor/index.js.map +1 -1
- package/build-module/components/welcome-guide/index.js +6 -3
- package/build-module/components/welcome-guide/index.js.map +1 -1
- package/build-module/editor.js +5 -6
- package/build-module/editor.js.map +1 -1
- package/build-module/editor.native.js +1 -2
- package/build-module/editor.native.js.map +1 -1
- package/build-module/index.js +3 -2
- package/build-module/index.js.map +1 -1
- package/build-module/plugins/welcome-guide-menu-item/index.js +2 -6
- package/build-module/plugins/welcome-guide-menu-item/index.js.map +1 -1
- package/build-module/store/actions.js +31 -36
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +1 -33
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +18 -9
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +63 -200
- package/build-style/style.css +63 -200
- package/package.json +32 -32
- package/src/components/header/header-toolbar/index.js +4 -0
- package/src/components/header/header-toolbar/style.scss +15 -13
- package/src/components/header/index.js +28 -13
- package/src/components/header/mode-switcher/index.js +2 -1
- package/src/components/header/more-menu/index.js +1 -0
- package/src/components/header/style.scss +60 -34
- package/src/components/header/writing-menu/index.js +16 -18
- package/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap +1 -1
- package/src/components/layout/index.js +13 -12
- package/src/components/preferences-modal/index.js +109 -96
- package/src/components/preferences-modal/test/index.js +1 -52
- package/src/components/sidebar/post-status/index.js +2 -2
- package/src/components/sidebar/settings-header/index.js +19 -71
- package/src/components/sidebar/settings-sidebar/index.js +117 -54
- package/src/components/sidebar/style.scss +4 -12
- package/src/components/start-page-options/index.js +3 -3
- package/src/components/visual-editor/index.js +26 -359
- package/src/components/visual-editor/style.scss +0 -15
- package/src/components/welcome-guide/index.js +4 -2
- package/src/editor.js +7 -7
- package/src/editor.native.js +3 -9
- package/src/index.js +3 -2
- package/src/plugins/welcome-guide-menu-item/index.js +3 -6
- package/src/store/actions.js +32 -46
- package/src/store/reducer.js +0 -33
- package/src/store/selectors.js +23 -9
- package/src/store/test/actions.js +0 -28
- package/src/style.scss +0 -3
- package/src/test/__snapshots__/editor.native.js.snap +21 -0
- package/src/test/editor.native.js +90 -56
- package/build/components/device-preview/index.js +0 -72
- package/build/components/device-preview/index.js.map +0 -1
- package/build/components/header/document-actions/index.js +0 -82
- package/build/components/header/document-actions/index.js.map +0 -1
- package/build/components/sidebar/post-template/create-modal.js +0 -99
- package/build/components/sidebar/post-template/create-modal.js.map +0 -1
- package/build/components/sidebar/post-template/form.js +0 -110
- package/build/components/sidebar/post-template/form.js.map +0 -1
- package/build/components/sidebar/post-template/index.js +0 -106
- package/build/components/sidebar/post-template/index.js.map +0 -1
- package/build-module/components/device-preview/index.js +0 -65
- package/build-module/components/device-preview/index.js.map +0 -1
- package/build-module/components/header/document-actions/index.js +0 -74
- package/build-module/components/header/document-actions/index.js.map +0 -1
- package/build-module/components/sidebar/post-template/create-modal.js +0 -92
- package/build-module/components/sidebar/post-template/create-modal.js.map +0 -1
- package/build-module/components/sidebar/post-template/form.js +0 -102
- package/build-module/components/sidebar/post-template/form.js.map +0 -1
- package/build-module/components/sidebar/post-template/index.js +0 -98
- package/build-module/components/sidebar/post-template/index.js.map +0 -1
- package/src/components/device-preview/index.js +0 -73
- package/src/components/header/document-actions/index.js +0 -82
- package/src/components/header/document-actions/style.scss +0 -64
- package/src/components/sidebar/post-template/create-modal.js +0 -140
- package/src/components/sidebar/post-template/form.js +0 -141
- package/src/components/sidebar/post-template/index.js +0 -120
- package/src/components/sidebar/post-template/style.scss +0 -22
- package/src/components/sidebar/settings-header/style.scss +0 -74
- package/src/components/sidebar/template/style.scss +0 -35
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = PostTemplateCreateModal;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _data = require("@wordpress/data");
|
|
9
|
-
var _editor = require("@wordpress/editor");
|
|
10
|
-
var _element = require("@wordpress/element");
|
|
11
|
-
var _blocks = require("@wordpress/blocks");
|
|
12
|
-
var _components = require("@wordpress/components");
|
|
13
|
-
var _i18n = require("@wordpress/i18n");
|
|
14
|
-
var _url = require("@wordpress/url");
|
|
15
|
-
var _store = require("../../../store");
|
|
16
|
-
/**
|
|
17
|
-
* WordPress dependencies
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Internal dependencies
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
const DEFAULT_TITLE = (0, _i18n.__)('Custom Template');
|
|
25
|
-
function PostTemplateCreateModal({
|
|
26
|
-
onClose
|
|
27
|
-
}) {
|
|
28
|
-
const defaultBlockTemplate = (0, _data.useSelect)(select => select(_editor.store).getEditorSettings().defaultBlockTemplate, []);
|
|
29
|
-
const {
|
|
30
|
-
__unstableCreateTemplate,
|
|
31
|
-
__unstableSwitchToTemplateMode
|
|
32
|
-
} = (0, _data.useDispatch)(_store.store);
|
|
33
|
-
const [title, setTitle] = (0, _element.useState)('');
|
|
34
|
-
const [isBusy, setIsBusy] = (0, _element.useState)(false);
|
|
35
|
-
const cancel = () => {
|
|
36
|
-
setTitle('');
|
|
37
|
-
onClose();
|
|
38
|
-
};
|
|
39
|
-
const submit = async event => {
|
|
40
|
-
event.preventDefault();
|
|
41
|
-
if (isBusy) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
setIsBusy(true);
|
|
45
|
-
const newTemplateContent = defaultBlockTemplate !== null && defaultBlockTemplate !== void 0 ? defaultBlockTemplate : (0, _blocks.serialize)([(0, _blocks.createBlock)('core/group', {
|
|
46
|
-
tagName: 'header',
|
|
47
|
-
layout: {
|
|
48
|
-
inherit: true
|
|
49
|
-
}
|
|
50
|
-
}, [(0, _blocks.createBlock)('core/site-title'), (0, _blocks.createBlock)('core/site-tagline')]), (0, _blocks.createBlock)('core/separator'), (0, _blocks.createBlock)('core/group', {
|
|
51
|
-
tagName: 'main'
|
|
52
|
-
}, [(0, _blocks.createBlock)('core/group', {
|
|
53
|
-
layout: {
|
|
54
|
-
inherit: true
|
|
55
|
-
}
|
|
56
|
-
}, [(0, _blocks.createBlock)('core/post-title')]), (0, _blocks.createBlock)('core/post-content', {
|
|
57
|
-
layout: {
|
|
58
|
-
inherit: true
|
|
59
|
-
}
|
|
60
|
-
})])]);
|
|
61
|
-
await __unstableCreateTemplate({
|
|
62
|
-
slug: (0, _url.cleanForSlug)(title || DEFAULT_TITLE),
|
|
63
|
-
content: newTemplateContent,
|
|
64
|
-
title: title || DEFAULT_TITLE
|
|
65
|
-
});
|
|
66
|
-
setIsBusy(false);
|
|
67
|
-
cancel();
|
|
68
|
-
__unstableSwitchToTemplateMode(true);
|
|
69
|
-
};
|
|
70
|
-
return (0, _react.createElement)(_components.Modal, {
|
|
71
|
-
title: (0, _i18n.__)('Create custom template'),
|
|
72
|
-
onRequestClose: cancel,
|
|
73
|
-
className: "edit-post-post-template__create-modal"
|
|
74
|
-
}, (0, _react.createElement)("form", {
|
|
75
|
-
className: "edit-post-post-template__create-form",
|
|
76
|
-
onSubmit: submit
|
|
77
|
-
}, (0, _react.createElement)(_components.__experimentalVStack, {
|
|
78
|
-
spacing: "3"
|
|
79
|
-
}, (0, _react.createElement)(_components.TextControl, {
|
|
80
|
-
__nextHasNoMarginBottom: true,
|
|
81
|
-
label: (0, _i18n.__)('Name'),
|
|
82
|
-
value: title,
|
|
83
|
-
onChange: setTitle,
|
|
84
|
-
placeholder: DEFAULT_TITLE,
|
|
85
|
-
disabled: isBusy,
|
|
86
|
-
help: (0, _i18n.__)('Describe the template, e.g. "Post with sidebar". A custom template can be manually applied to any post or page.')
|
|
87
|
-
}), (0, _react.createElement)(_components.__experimentalHStack, {
|
|
88
|
-
justify: "right"
|
|
89
|
-
}, (0, _react.createElement)(_components.Button, {
|
|
90
|
-
variant: "tertiary",
|
|
91
|
-
onClick: cancel
|
|
92
|
-
}, (0, _i18n.__)('Cancel')), (0, _react.createElement)(_components.Button, {
|
|
93
|
-
variant: "primary",
|
|
94
|
-
type: "submit",
|
|
95
|
-
isBusy: isBusy,
|
|
96
|
-
"aria-disabled": isBusy
|
|
97
|
-
}, (0, _i18n.__)('Create'))))));
|
|
98
|
-
}
|
|
99
|
-
//# sourceMappingURL=create-modal.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_editor","_element","_blocks","_components","_i18n","_url","_store","DEFAULT_TITLE","__","PostTemplateCreateModal","onClose","defaultBlockTemplate","useSelect","select","editorStore","getEditorSettings","__unstableCreateTemplate","__unstableSwitchToTemplateMode","useDispatch","editPostStore","title","setTitle","useState","isBusy","setIsBusy","cancel","submit","event","preventDefault","newTemplateContent","serialize","createBlock","tagName","layout","inherit","slug","cleanForSlug","content","_react","createElement","Modal","onRequestClose","className","onSubmit","__experimentalVStack","spacing","TextControl","__nextHasNoMarginBottom","label","value","onChange","placeholder","disabled","help","__experimentalHStack","justify","Button","variant","onClick","type"],"sources":["@wordpress/edit-post/src/components/sidebar/post-template/create-modal.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { useState } from '@wordpress/element';\nimport { serialize, createBlock } from '@wordpress/blocks';\nimport {\n\tModal,\n\tTextControl,\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { cleanForSlug } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { store as editPostStore } from '../../../store';\n\nconst DEFAULT_TITLE = __( 'Custom Template' );\n\nexport default function PostTemplateCreateModal( { onClose } ) {\n\tconst defaultBlockTemplate = useSelect(\n\t\t( select ) =>\n\t\t\tselect( editorStore ).getEditorSettings().defaultBlockTemplate,\n\t\t[]\n\t);\n\n\tconst { __unstableCreateTemplate, __unstableSwitchToTemplateMode } =\n\t\tuseDispatch( editPostStore );\n\n\tconst [ title, setTitle ] = useState( '' );\n\n\tconst [ isBusy, setIsBusy ] = useState( false );\n\n\tconst cancel = () => {\n\t\tsetTitle( '' );\n\t\tonClose();\n\t};\n\n\tconst submit = async ( 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\tconst newTemplateContent =\n\t\t\tdefaultBlockTemplate ??\n\t\t\tserialize( [\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/group',\n\t\t\t\t\t{\n\t\t\t\t\t\ttagName: 'header',\n\t\t\t\t\t\tlayout: { inherit: true },\n\t\t\t\t\t},\n\t\t\t\t\t[\n\t\t\t\t\t\tcreateBlock( 'core/site-title' ),\n\t\t\t\t\t\tcreateBlock( 'core/site-tagline' ),\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t\t\tcreateBlock( 'core/separator' ),\n\t\t\t\tcreateBlock(\n\t\t\t\t\t'core/group',\n\t\t\t\t\t{\n\t\t\t\t\t\ttagName: 'main',\n\t\t\t\t\t},\n\t\t\t\t\t[\n\t\t\t\t\t\tcreateBlock(\n\t\t\t\t\t\t\t'core/group',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlayout: { inherit: true },\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t[ createBlock( 'core/post-title' ) ]\n\t\t\t\t\t\t),\n\t\t\t\t\t\tcreateBlock( 'core/post-content', {\n\t\t\t\t\t\t\tlayout: { inherit: true },\n\t\t\t\t\t\t} ),\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t\t] );\n\n\t\tawait __unstableCreateTemplate( {\n\t\t\tslug: cleanForSlug( title || DEFAULT_TITLE ),\n\t\t\tcontent: newTemplateContent,\n\t\t\ttitle: title || DEFAULT_TITLE,\n\t\t} );\n\n\t\tsetIsBusy( false );\n\t\tcancel();\n\n\t\t__unstableSwitchToTemplateMode( true );\n\t};\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ __( 'Create custom template' ) }\n\t\t\tonRequestClose={ cancel }\n\t\t\tclassName=\"edit-post-post-template__create-modal\"\n\t\t>\n\t\t\t<form\n\t\t\t\tclassName=\"edit-post-post-template__create-form\"\n\t\t\t\tonSubmit={ submit }\n\t\t\t>\n\t\t\t\t<VStack spacing=\"3\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\tplaceholder={ DEFAULT_TITLE }\n\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t'Describe the template, e.g. \"Post with sidebar\". A custom template can be manually applied to any post or page.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button variant=\"tertiary\" onClick={ cancel }>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\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</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t</Modal>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AAOA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,IAAA,GAAAN,OAAA;AAKA,IAAAO,MAAA,GAAAP,OAAA;AApBA;AACA;AACA;;AAeA;AACA;AACA;;AAGA,MAAMQ,aAAa,GAAG,IAAAC,QAAE,EAAE,iBAAkB,CAAC;AAE9B,SAASC,uBAAuBA,CAAE;EAAEC;AAAQ,CAAC,EAAG;EAC9D,MAAMC,oBAAoB,GAAG,IAAAC,eAAS,EACnCC,MAAM,IACPA,MAAM,CAAEC,aAAY,CAAC,CAACC,iBAAiB,CAAC,CAAC,CAACJ,oBAAoB,EAC/D,EACD,CAAC;EAED,MAAM;IAAEK,wBAAwB;IAAEC;EAA+B,CAAC,GACjE,IAAAC,iBAAW,EAAEC,YAAc,CAAC;EAE7B,MAAM,CAAEC,KAAK,EAAEC,QAAQ,CAAE,GAAG,IAAAC,iBAAQ,EAAE,EAAG,CAAC;EAE1C,MAAM,CAA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+0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = PostTemplateForm;
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
var _element = require("@wordpress/element");
|
|
10
|
-
var _blockEditor = require("@wordpress/block-editor");
|
|
11
|
-
var _i18n = require("@wordpress/i18n");
|
|
12
|
-
var _icons = require("@wordpress/icons");
|
|
13
|
-
var _components = require("@wordpress/components");
|
|
14
|
-
var _data = require("@wordpress/data");
|
|
15
|
-
var _editor = require("@wordpress/editor");
|
|
16
|
-
var _coreData = require("@wordpress/core-data");
|
|
17
|
-
var _store = require("../../../store");
|
|
18
|
-
var _createModal = _interopRequireDefault(require("./create-modal"));
|
|
19
|
-
/**
|
|
20
|
-
* WordPress dependencies
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Internal dependencies
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
function PostTemplateForm({
|
|
28
|
-
onClose
|
|
29
|
-
}) {
|
|
30
|
-
var _options$find, _selectedOption$value;
|
|
31
|
-
const {
|
|
32
|
-
isPostsPage,
|
|
33
|
-
availableTemplates,
|
|
34
|
-
fetchedTemplates,
|
|
35
|
-
selectedTemplateSlug,
|
|
36
|
-
canCreate,
|
|
37
|
-
canEdit
|
|
38
|
-
} = (0, _data.useSelect)(select => {
|
|
39
|
-
const {
|
|
40
|
-
canUser,
|
|
41
|
-
getEntityRecord,
|
|
42
|
-
getEntityRecords
|
|
43
|
-
} = select(_coreData.store);
|
|
44
|
-
const editorSettings = select(_editor.store).getEditorSettings();
|
|
45
|
-
const siteSettings = canUser('read', 'settings') ? getEntityRecord('root', 'site') : undefined;
|
|
46
|
-
const _isPostsPage = select(_editor.store).getCurrentPostId() === siteSettings?.page_for_posts;
|
|
47
|
-
const canCreateTemplates = canUser('create', 'templates');
|
|
48
|
-
return {
|
|
49
|
-
isPostsPage: _isPostsPage,
|
|
50
|
-
availableTemplates: editorSettings.availableTemplates,
|
|
51
|
-
fetchedTemplates: canCreateTemplates ? getEntityRecords('postType', 'wp_template', {
|
|
52
|
-
post_type: select(_editor.store).getCurrentPostType(),
|
|
53
|
-
per_page: -1
|
|
54
|
-
}) : undefined,
|
|
55
|
-
selectedTemplateSlug: select(_editor.store).getEditedPostAttribute('template'),
|
|
56
|
-
canCreate: canCreateTemplates && !_isPostsPage && editorSettings.supportsTemplateMode,
|
|
57
|
-
canEdit: canCreateTemplates && editorSettings.supportsTemplateMode && !!select(_store.store).getEditedPostTemplate()
|
|
58
|
-
};
|
|
59
|
-
}, []);
|
|
60
|
-
const options = (0, _element.useMemo)(() => Object.entries({
|
|
61
|
-
...availableTemplates,
|
|
62
|
-
...Object.fromEntries((fetchedTemplates !== null && fetchedTemplates !== void 0 ? fetchedTemplates : []).map(({
|
|
63
|
-
slug,
|
|
64
|
-
title
|
|
65
|
-
}) => [slug, title.rendered]))
|
|
66
|
-
}).map(([slug, title]) => ({
|
|
67
|
-
value: slug,
|
|
68
|
-
label: title
|
|
69
|
-
})), [availableTemplates, fetchedTemplates]);
|
|
70
|
-
const selectedOption = (_options$find = options.find(option => option.value === selectedTemplateSlug)) !== null && _options$find !== void 0 ? _options$find : options.find(option => !option.value); // The default option has '' value.
|
|
71
|
-
|
|
72
|
-
const {
|
|
73
|
-
editPost
|
|
74
|
-
} = (0, _data.useDispatch)(_editor.store);
|
|
75
|
-
const {
|
|
76
|
-
__unstableSwitchToTemplateMode
|
|
77
|
-
} = (0, _data.useDispatch)(_store.store);
|
|
78
|
-
const [isCreateModalOpen, setIsCreateModalOpen] = (0, _element.useState)(false);
|
|
79
|
-
return (0, _react.createElement)("div", {
|
|
80
|
-
className: "edit-post-post-template__form"
|
|
81
|
-
}, (0, _react.createElement)(_blockEditor.__experimentalInspectorPopoverHeader, {
|
|
82
|
-
title: (0, _i18n.__)('Template'),
|
|
83
|
-
help: (0, _i18n.__)('Templates define the way content is displayed when viewing your site.'),
|
|
84
|
-
actions: canCreate ? [{
|
|
85
|
-
icon: _icons.addTemplate,
|
|
86
|
-
label: (0, _i18n.__)('Add template'),
|
|
87
|
-
onClick: () => setIsCreateModalOpen(true)
|
|
88
|
-
}] : [],
|
|
89
|
-
onClose: onClose
|
|
90
|
-
}), isPostsPage ? (0, _react.createElement)(_components.Notice, {
|
|
91
|
-
className: "edit-post-post-template__notice",
|
|
92
|
-
status: "warning",
|
|
93
|
-
isDismissible: false
|
|
94
|
-
}, (0, _i18n.__)('The posts page template cannot be changed.')) : (0, _react.createElement)(_components.SelectControl, {
|
|
95
|
-
__nextHasNoMarginBottom: true,
|
|
96
|
-
hideLabelFromVision: true,
|
|
97
|
-
label: (0, _i18n.__)('Template'),
|
|
98
|
-
value: (_selectedOption$value = selectedOption?.value) !== null && _selectedOption$value !== void 0 ? _selectedOption$value : '',
|
|
99
|
-
options: options,
|
|
100
|
-
onChange: slug => editPost({
|
|
101
|
-
template: slug || ''
|
|
102
|
-
})
|
|
103
|
-
}), canEdit && (0, _react.createElement)("p", null, (0, _react.createElement)(_components.Button, {
|
|
104
|
-
variant: "link",
|
|
105
|
-
onClick: () => __unstableSwitchToTemplateMode()
|
|
106
|
-
}, (0, _i18n.__)('Edit template'))), isCreateModalOpen && (0, _react.createElement)(_createModal.default, {
|
|
107
|
-
onClose: () => setIsCreateModalOpen(false)
|
|
108
|
-
}));
|
|
109
|
-
}
|
|
110
|
-
//# sourceMappingURL=form.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_blockEditor","_i18n","_icons","_components","_data","_editor","_coreData","_store","_createModal","_interopRequireDefault","PostTemplateForm","onClose","_options$find","_selectedOption$value","isPostsPage","availableTemplates","fetchedTemplates","selectedTemplateSlug","canCreate","canEdit","useSelect","select","canUser","getEntityRecord","getEntityRecords","coreStore","editorSettings","editorStore","getEditorSettings","siteSettings","undefined","_isPostsPage","getCurrentPostId","page_for_posts","canCreateTemplates","post_type","getCurrentPostType","per_page","getEditedPostAttribute","supportsTemplateMode","editPostStore","getEditedPostTemplate","options","useMemo","Object","entries","fromEntries","map","slug","title","rendered","value","label","selectedOption","find","option","editPost","useDispatch","__unstableSwitchToTemplateMode","isCreateModalOpen","setIsCreateModalOpen","useState","_react","createElement","className","__experimentalInspectorPopoverHeader","__","help","actions","icon","addTemplate","onClick","Notice","status","isDismissible","SelectControl","__nextHasNoMarginBottom","hideLabelFromVision","onChange","template","Button","variant","default"],"sources":["@wordpress/edit-post/src/components/sidebar/post-template/form.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useMemo } from '@wordpress/element';\nimport { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '@wordpress/block-editor';\nimport { __ } from '@wordpress/i18n';\nimport { addTemplate } from '@wordpress/icons';\nimport { Notice, SelectControl, Button } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editPostStore } from '../../../store';\nimport PostTemplateCreateModal from './create-modal';\n\nexport default function PostTemplateForm( { onClose } ) {\n\tconst {\n\t\tisPostsPage,\n\t\tavailableTemplates,\n\t\tfetchedTemplates,\n\t\tselectedTemplateSlug,\n\t\tcanCreate,\n\t\tcanEdit,\n\t} = useSelect( ( select ) => {\n\t\tconst { canUser, getEntityRecord, getEntityRecords } =\n\t\t\tselect( coreStore );\n\t\tconst editorSettings = select( editorStore ).getEditorSettings();\n\t\tconst siteSettings = canUser( 'read', 'settings' )\n\t\t\t? getEntityRecord( 'root', 'site' )\n\t\t\t: undefined;\n\t\tconst _isPostsPage =\n\t\t\tselect( editorStore ).getCurrentPostId() ===\n\t\t\tsiteSettings?.page_for_posts;\n\t\tconst canCreateTemplates = canUser( 'create', 'templates' );\n\n\t\treturn {\n\t\t\tisPostsPage: _isPostsPage,\n\t\t\tavailableTemplates: editorSettings.availableTemplates,\n\t\t\tfetchedTemplates: canCreateTemplates\n\t\t\t\t? getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\t\t\tpost_type: select( editorStore ).getCurrentPostType(),\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t } )\n\t\t\t\t: undefined,\n\t\t\tselectedTemplateSlug:\n\t\t\t\tselect( editorStore ).getEditedPostAttribute( 'template' ),\n\t\t\tcanCreate:\n\t\t\t\tcanCreateTemplates &&\n\t\t\t\t! _isPostsPage &&\n\t\t\t\teditorSettings.supportsTemplateMode,\n\t\t\tcanEdit:\n\t\t\t\tcanCreateTemplates &&\n\t\t\t\teditorSettings.supportsTemplateMode &&\n\t\t\t\t!! select( editPostStore ).getEditedPostTemplate(),\n\t\t};\n\t}, [] );\n\n\tconst options = useMemo(\n\t\t() =>\n\t\t\tObject.entries( {\n\t\t\t\t...availableTemplates,\n\t\t\t\t...Object.fromEntries(\n\t\t\t\t\t( fetchedTemplates ?? [] ).map( ( { slug, title } ) => [\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\ttitle.rendered,\n\t\t\t\t\t] )\n\t\t\t\t),\n\t\t\t} ).map( ( [ slug, title ] ) => ( { value: slug, label: title } ) ),\n\t\t[ availableTemplates, fetchedTemplates ]\n\t);\n\n\tconst selectedOption =\n\t\toptions.find( ( option ) => option.value === selectedTemplateSlug ) ??\n\t\toptions.find( ( option ) => ! option.value ); // The default option has '' value.\n\n\tconst { editPost } = useDispatch( editorStore );\n\tconst { __unstableSwitchToTemplateMode } = useDispatch( editPostStore );\n\n\tconst [ isCreateModalOpen, setIsCreateModalOpen ] = useState( false );\n\n\treturn (\n\t\t<div className=\"edit-post-post-template__form\">\n\t\t\t<InspectorPopoverHeader\n\t\t\t\ttitle={ __( 'Template' ) }\n\t\t\t\thelp={ __(\n\t\t\t\t\t'Templates define the way content is displayed when viewing your site.'\n\t\t\t\t) }\n\t\t\t\tactions={\n\t\t\t\t\tcanCreate\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ticon: addTemplate,\n\t\t\t\t\t\t\t\t\tlabel: __( 'Add template' ),\n\t\t\t\t\t\t\t\t\tonClick: () => setIsCreateModalOpen( true ),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t ]\n\t\t\t\t\t\t: []\n\t\t\t\t}\n\t\t\t\tonClose={ onClose }\n\t\t\t/>\n\t\t\t{ isPostsPage ? (\n\t\t\t\t<Notice\n\t\t\t\t\tclassName=\"edit-post-post-template__notice\"\n\t\t\t\t\tstatus=\"warning\"\n\t\t\t\t\tisDismissible={ false }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'The posts page template cannot be changed.' ) }\n\t\t\t\t</Notice>\n\t\t\t) : (\n\t\t\t\t<SelectControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t\tlabel={ __( 'Template' ) }\n\t\t\t\t\tvalue={ selectedOption?.value ?? '' }\n\t\t\t\t\toptions={ options }\n\t\t\t\t\tonChange={ ( slug ) =>\n\t\t\t\t\t\teditPost( { template: slug || '' } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ canEdit && (\n\t\t\t\t<p>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"link\"\n\t\t\t\t\t\tonClick={ () => __unstableSwitchToTemplateMode() }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Edit template' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</p>\n\t\t\t) }\n\t\t\t{ isCreateModalOpen && (\n\t\t\t\t<PostTemplateCreateModal\n\t\t\t\t\tonClose={ () => setIsCreateModalOpen( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAA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AAAC,aAAA,aACC,IAAAD,MAAA,CAAAC,aAAA,EAAC5D,WAAA,CAAA6E,MAAM;IACNC,OAAO,EAAC,MAAM;IACdV,OAAO,EAAGA,CAAA,KAAMb,8BAA8B,CAAC;EAAG,GAEhD,IAAAQ,QAAE,EAAE,eAAgB,CACf,CACN,CACH,EACCP,iBAAiB,IAClB,IAAAG,MAAA,CAAAC,aAAA,EAACvD,YAAA,CAAA0E,OAAuB;IACvBvE,OAAO,EAAGA,CAAA,KAAMiD,oBAAoB,CAAE,KAAM;EAAG,CAC/C,CAEE,CAAC;AAER"}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = PostTemplate;
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
var _element = require("@wordpress/element");
|
|
10
|
-
var _components = require("@wordpress/components");
|
|
11
|
-
var _i18n = require("@wordpress/i18n");
|
|
12
|
-
var _data = require("@wordpress/data");
|
|
13
|
-
var _editor = require("@wordpress/editor");
|
|
14
|
-
var _coreData = require("@wordpress/core-data");
|
|
15
|
-
var _form = _interopRequireDefault(require("./form"));
|
|
16
|
-
var _store = require("../../../store");
|
|
17
|
-
var _lockUnlock = require("../../../lock-unlock");
|
|
18
|
-
/**
|
|
19
|
-
* WordPress dependencies
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Internal dependencies
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
const {
|
|
27
|
-
PostPanelRow
|
|
28
|
-
} = (0, _lockUnlock.unlock)(_editor.privateApis);
|
|
29
|
-
function PostTemplate() {
|
|
30
|
-
// Use internal state instead of a ref to make sure that the component
|
|
31
|
-
// re-renders when the popover's anchor updates.
|
|
32
|
-
const [popoverAnchor, setPopoverAnchor] = (0, _element.useState)(null);
|
|
33
|
-
// Memoize popoverProps to avoid returning a new object every time.
|
|
34
|
-
const popoverProps = (0, _element.useMemo)(() => ({
|
|
35
|
-
anchor: popoverAnchor,
|
|
36
|
-
placement: 'bottom-end'
|
|
37
|
-
}), [popoverAnchor]);
|
|
38
|
-
const isVisible = (0, _data.useSelect)(select => {
|
|
39
|
-
var _select$canUser;
|
|
40
|
-
const postTypeSlug = select(_editor.store).getCurrentPostType();
|
|
41
|
-
const postType = select(_coreData.store).getPostType(postTypeSlug);
|
|
42
|
-
if (!postType?.viewable) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
const settings = select(_editor.store).getEditorSettings();
|
|
46
|
-
const hasTemplates = !!settings.availableTemplates && Object.keys(settings.availableTemplates).length > 0;
|
|
47
|
-
if (hasTemplates) {
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
if (!settings.supportsTemplateMode) {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
const canCreateTemplates = (_select$canUser = select(_coreData.store).canUser('create', 'templates')) !== null && _select$canUser !== void 0 ? _select$canUser : false;
|
|
54
|
-
return canCreateTemplates;
|
|
55
|
-
}, []);
|
|
56
|
-
if (!isVisible) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
return (0, _react.createElement)(PostPanelRow, {
|
|
60
|
-
label: (0, _i18n.__)('Template'),
|
|
61
|
-
ref: setPopoverAnchor
|
|
62
|
-
}, (0, _react.createElement)(_components.Dropdown, {
|
|
63
|
-
popoverProps: popoverProps,
|
|
64
|
-
contentClassName: "edit-post-post-template__dialog",
|
|
65
|
-
focusOnMount: true,
|
|
66
|
-
renderToggle: ({
|
|
67
|
-
isOpen,
|
|
68
|
-
onToggle
|
|
69
|
-
}) => (0, _react.createElement)(PostTemplateToggle, {
|
|
70
|
-
isOpen: isOpen,
|
|
71
|
-
onClick: onToggle
|
|
72
|
-
}),
|
|
73
|
-
renderContent: ({
|
|
74
|
-
onClose
|
|
75
|
-
}) => (0, _react.createElement)(_form.default, {
|
|
76
|
-
onClose: onClose
|
|
77
|
-
})
|
|
78
|
-
}));
|
|
79
|
-
}
|
|
80
|
-
function PostTemplateToggle({
|
|
81
|
-
isOpen,
|
|
82
|
-
onClick
|
|
83
|
-
}) {
|
|
84
|
-
const templateTitle = (0, _data.useSelect)(select => {
|
|
85
|
-
const templateSlug = select(_editor.store).getEditedPostAttribute('template');
|
|
86
|
-
const {
|
|
87
|
-
supportsTemplateMode,
|
|
88
|
-
availableTemplates
|
|
89
|
-
} = select(_editor.store).getEditorSettings();
|
|
90
|
-
if (!supportsTemplateMode && availableTemplates[templateSlug]) {
|
|
91
|
-
return availableTemplates[templateSlug];
|
|
92
|
-
}
|
|
93
|
-
const template = select(_coreData.store).canUser('create', 'templates') && select(_store.store).getEditedPostTemplate();
|
|
94
|
-
return template?.title || template?.slug || availableTemplates?.[templateSlug];
|
|
95
|
-
}, []);
|
|
96
|
-
return (0, _react.createElement)(_components.Button, {
|
|
97
|
-
className: "edit-post-post-template__toggle",
|
|
98
|
-
variant: "tertiary",
|
|
99
|
-
"aria-expanded": isOpen,
|
|
100
|
-
"aria-label": templateTitle ? (0, _i18n.sprintf)(
|
|
101
|
-
// translators: %s: Name of the currently selected template.
|
|
102
|
-
(0, _i18n.__)('Select template: %s'), templateTitle) : (0, _i18n.__)('Select template'),
|
|
103
|
-
onClick: onClick
|
|
104
|
-
}, templateTitle !== null && templateTitle !== void 0 ? templateTitle : (0, _i18n.__)('Default template'));
|
|
105
|
-
}
|
|
106
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_components","_i18n","_data","_editor","_coreData","_form","_interopRequireDefault","_store","_lockUnlock","PostPanelRow","unlock","editorPrivateApis","PostTemplate","popoverAnchor","setPopoverAnchor","useState","popoverProps","useMemo","anchor","placement","isVisible","useSelect","select","_select$canUser","postTypeSlug","editorStore","getCurrentPostType","postType","coreStore","getPostType","viewable","settings","getEditorSettings","hasTemplates","availableTemplates","Object","keys","length","supportsTemplateMode","canCreateTemplates","canUser","_react","createElement","label","__","ref","Dropdown","contentClassName","focusOnMount","renderToggle","isOpen","onToggle","PostTemplateToggle","onClick","renderContent","onClose","default","templateTitle","templateSlug","getEditedPostAttribute","template","editPostStore","getEditedPostTemplate","title","slug","Button","className","variant","sprintf"],"sources":["@wordpress/edit-post/src/components/sidebar/post-template/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useMemo } from '@wordpress/element';\nimport { Dropdown, Button } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tstore as editorStore,\n\tprivateApis as editorPrivateApis,\n} from '@wordpress/editor';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport PostTemplateForm from './form';\nimport { store as editPostStore } from '../../../store';\nimport { unlock } from '../../../lock-unlock';\n\nconst { PostPanelRow } = unlock( editorPrivateApis );\n\nexport default function PostTemplate() {\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\t// Memoize popoverProps to avoid returning a new object every time.\n\tconst popoverProps = useMemo(\n\t\t() => ( { anchor: popoverAnchor, placement: 'bottom-end' } ),\n\t\t[ popoverAnchor ]\n\t);\n\n\tconst isVisible = useSelect( ( select ) => {\n\t\tconst postTypeSlug = select( editorStore ).getCurrentPostType();\n\t\tconst postType = select( coreStore ).getPostType( postTypeSlug );\n\t\tif ( ! postType?.viewable ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst settings = select( editorStore ).getEditorSettings();\n\t\tconst hasTemplates =\n\t\t\t!! settings.availableTemplates &&\n\t\t\tObject.keys( settings.availableTemplates ).length > 0;\n\t\tif ( hasTemplates ) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif ( ! settings.supportsTemplateMode ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst canCreateTemplates =\n\t\t\tselect( coreStore ).canUser( 'create', 'templates' ) ?? false;\n\t\treturn canCreateTemplates;\n\t}, [] );\n\n\tif ( ! isVisible ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<PostPanelRow label={ __( 'Template' ) } ref={ setPopoverAnchor }>\n\t\t\t<Dropdown\n\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\tcontentClassName=\"edit-post-post-template__dialog\"\n\t\t\t\tfocusOnMount\n\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t<PostTemplateToggle\n\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t<PostTemplateForm onClose={ onClose } />\n\t\t\t\t) }\n\t\t\t/>\n\t\t</PostPanelRow>\n\t);\n}\n\nfunction PostTemplateToggle( { isOpen, onClick } ) {\n\tconst templateTitle = useSelect( ( select ) => {\n\t\tconst templateSlug =\n\t\t\tselect( editorStore ).getEditedPostAttribute( 'template' );\n\n\t\tconst { supportsTemplateMode, availableTemplates } =\n\t\t\tselect( editorStore ).getEditorSettings();\n\t\tif ( ! supportsTemplateMode && availableTemplates[ templateSlug ] ) {\n\t\t\treturn availableTemplates[ templateSlug ];\n\t\t}\n\t\tconst template =\n\t\t\tselect( coreStore ).canUser( 'create', 'templates' ) &&\n\t\t\tselect( editPostStore ).getEditedPostTemplate();\n\t\treturn (\n\t\t\ttemplate?.title ||\n\t\t\ttemplate?.slug ||\n\t\t\tavailableTemplates?.[ templateSlug ]\n\t\t);\n\t}, [] );\n\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"edit-post-post-template__toggle\"\n\t\t\tvariant=\"tertiary\"\n\t\t\taria-expanded={ isOpen }\n\t\t\taria-label={\n\t\t\t\ttemplateTitle\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t// translators: %s: Name of the currently selected template.\n\t\t\t\t\t\t\t__( 'Select template: %s' ),\n\t\t\t\t\t\t\ttemplateTitle\n\t\t\t\t\t )\n\t\t\t\t\t: __( 'Select template' )\n\t\t\t}\n\t\t\tonClick={ onClick }\n\t\t>\n\t\t\t{ templateTitle ?? __( 'Default template' ) }\n\t\t</Button>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAIA,IAAAK,SAAA,GAAAL,OAAA;AAKA,IAAAM,KAAA,GAAAC,sBAAA,CAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA;AACA,IAAAS,WAAA,GAAAT,OAAA;AAlBA;AACA;AACA;;AAWA;AACA;AACA;;AAKA,MAAM;EAAEU;AAAa,CAAC,GAAG,IAAAC,kBAAM,EAAEC,mBAAkB,CAAC;AAErC,SAASC,YAAYA,CAAA,EAAG;EACtC;EACA;EACA,MAAM,CAAEC,aAAa,EAAEC,gBAAgB,CAAE,GAAG,IAAAC,iBAAQ,EAAE,IAAK,CAAC;EAC5D;EACA,MAAMC,YAAY,GAAG,IAAAC,gBAAO,EAC3B,OAAQ;IAAEC,MAAM,EAAEL,aAAa;IAAEM,SAAS,EAAE;EAAa,CAAC,CAAE,EAC5D,CAAEN,aAAa,CAChB,CAAC;EAED,MAAMO,SAAS,GAAG,IAAAC,eAAS,EAAIC,MAAM,IAAM;IAAA,IAAAC,eAAA;IAC1C,MAAMC,YAAY,GAAGF,MAAM,CAAEG,aAAY,CAAC,CAACC,kBAAkB,CAAC,CAAC;IAC/D,MAAMC,QAAQ,GAAGL,MAAM,CAAEM,eAAU,CAAC,CAACC,WAAW,CAAEL,YAAa,CAAC;IAChE,IAAK,CAAEG,QAAQ,EAAEG,QAAQ,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WordPress dependencies
|
|
4
|
-
*/
|
|
5
|
-
import { Icon, MenuGroup } from '@wordpress/components';
|
|
6
|
-
import { PostPreviewButton, store as editorStore } from '@wordpress/editor';
|
|
7
|
-
import { external } from '@wordpress/icons';
|
|
8
|
-
import { __ } from '@wordpress/i18n';
|
|
9
|
-
import { __experimentalPreviewOptions as PreviewOptions } from '@wordpress/block-editor';
|
|
10
|
-
import { useDispatch, useSelect } from '@wordpress/data';
|
|
11
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Internal dependencies
|
|
15
|
-
*/
|
|
16
|
-
import { store as editPostStore } from '../../store';
|
|
17
|
-
export default function DevicePreview() {
|
|
18
|
-
const {
|
|
19
|
-
hasActiveMetaboxes,
|
|
20
|
-
isPostSaveable,
|
|
21
|
-
isViewable,
|
|
22
|
-
deviceType,
|
|
23
|
-
showIconLabels
|
|
24
|
-
} = useSelect(select => {
|
|
25
|
-
var _postType$viewable;
|
|
26
|
-
const {
|
|
27
|
-
getEditedPostAttribute
|
|
28
|
-
} = select(editorStore);
|
|
29
|
-
const {
|
|
30
|
-
getPostType
|
|
31
|
-
} = select(coreStore);
|
|
32
|
-
const postType = getPostType(getEditedPostAttribute('type'));
|
|
33
|
-
return {
|
|
34
|
-
hasActiveMetaboxes: select(editPostStore).hasMetaBoxes(),
|
|
35
|
-
isPostSaveable: select(editorStore).isEditedPostSaveable(),
|
|
36
|
-
isViewable: (_postType$viewable = postType?.viewable) !== null && _postType$viewable !== void 0 ? _postType$viewable : false,
|
|
37
|
-
deviceType: select(editPostStore).__experimentalGetPreviewDeviceType(),
|
|
38
|
-
showIconLabels: select(editPostStore).isFeatureActive('showIconLabels')
|
|
39
|
-
};
|
|
40
|
-
}, []);
|
|
41
|
-
const {
|
|
42
|
-
__experimentalSetPreviewDeviceType: setPreviewDeviceType
|
|
43
|
-
} = useDispatch(editPostStore);
|
|
44
|
-
return createElement(PreviewOptions, {
|
|
45
|
-
isEnabled: isPostSaveable,
|
|
46
|
-
className: "edit-post-post-preview-dropdown",
|
|
47
|
-
deviceType: deviceType,
|
|
48
|
-
setDeviceType: setPreviewDeviceType,
|
|
49
|
-
label: __('Preview'),
|
|
50
|
-
showIconLabels: showIconLabels
|
|
51
|
-
}, ({
|
|
52
|
-
onClose
|
|
53
|
-
}) => isViewable && createElement(MenuGroup, null, createElement("div", {
|
|
54
|
-
className: "edit-post-header-preview__grouping-external"
|
|
55
|
-
}, createElement(PostPreviewButton, {
|
|
56
|
-
className: "edit-post-header-preview__button-external",
|
|
57
|
-
role: "menuitem",
|
|
58
|
-
forceIsAutosaveable: hasActiveMetaboxes,
|
|
59
|
-
textContent: createElement(Fragment, null, __('Preview in new tab'), createElement(Icon, {
|
|
60
|
-
icon: external
|
|
61
|
-
})),
|
|
62
|
-
onPreview: onClose
|
|
63
|
-
}))));
|
|
64
|
-
}
|
|
65
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["Icon","MenuGroup","PostPreviewButton","store","editorStore","external","__","__experimentalPreviewOptions","PreviewOptions","useDispatch","useSelect","coreStore","editPostStore","DevicePreview","hasActiveMetaboxes","isPostSaveable","isViewable","deviceType","showIconLabels","select","_postType$viewable","getEditedPostAttribute","getPostType","postType","hasMetaBoxes","isEditedPostSaveable","viewable","__experimentalGetPreviewDeviceType","isFeatureActive","__experimentalSetPreviewDeviceType","setPreviewDeviceType","createElement","isEnabled","className","setDeviceType","label","onClose","role","forceIsAutosaveable","textContent","Fragment","icon","onPreview"],"sources":["@wordpress/edit-post/src/components/device-preview/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Icon, MenuGroup } from '@wordpress/components';\nimport { PostPreviewButton, store as editorStore } from '@wordpress/editor';\nimport { external } from '@wordpress/icons';\nimport { __ } from '@wordpress/i18n';\nimport { __experimentalPreviewOptions as PreviewOptions } from '@wordpress/block-editor';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { store as editPostStore } from '../../store';\n\nexport default function DevicePreview() {\n\tconst {\n\t\thasActiveMetaboxes,\n\t\tisPostSaveable,\n\t\tisViewable,\n\t\tdeviceType,\n\t\tshowIconLabels,\n\t} = useSelect( ( select ) => {\n\t\tconst { getEditedPostAttribute } = select( editorStore );\n\t\tconst { getPostType } = select( coreStore );\n\t\tconst postType = getPostType( getEditedPostAttribute( 'type' ) );\n\n\t\treturn {\n\t\t\thasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(),\n\t\t\tisPostSaveable: select( editorStore ).isEditedPostSaveable(),\n\t\t\tisViewable: postType?.viewable ?? false,\n\t\t\tdeviceType:\n\t\t\t\tselect( editPostStore ).__experimentalGetPreviewDeviceType(),\n\t\t\tshowIconLabels:\n\t\t\t\tselect( editPostStore ).isFeatureActive( 'showIconLabels' ),\n\t\t};\n\t}, [] );\n\tconst { __experimentalSetPreviewDeviceType: setPreviewDeviceType } =\n\t\tuseDispatch( editPostStore );\n\n\treturn (\n\t\t<PreviewOptions\n\t\t\tisEnabled={ isPostSaveable }\n\t\t\tclassName=\"edit-post-post-preview-dropdown\"\n\t\t\tdeviceType={ deviceType }\n\t\t\tsetDeviceType={ setPreviewDeviceType }\n\t\t\tlabel={ __( 'Preview' ) }\n\t\t\tshowIconLabels={ showIconLabels }\n\t\t>\n\t\t\t{ ( { onClose } ) =>\n\t\t\t\tisViewable && (\n\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t<div className=\"edit-post-header-preview__grouping-external\">\n\t\t\t\t\t\t\t<PostPreviewButton\n\t\t\t\t\t\t\t\tclassName=\"edit-post-header-preview__button-external\"\n\t\t\t\t\t\t\t\trole=\"menuitem\"\n\t\t\t\t\t\t\t\tforceIsAutosaveable={ hasActiveMetaboxes }\n\t\t\t\t\t\t\t\ttextContent={\n\t\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t\t{ __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,GAAEG,QAAQ,EAAEG,QAAQ,cAAAN,kBAAA,cAAAA,kBAAA,GAAI,KAAK;MACvCH,UAAU,EACTE,MAAM,CAAEP,aAAc,CAAC,CAACe,kCAAkC,CAAC,CAAC;MAC7DT,cAAc,EACbC,MAAM,CAAEP,aAAc,CAAC,CAACgB,eAAe,CAAE,gBAAiB;IAC5D,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EACP,MAAM;IAAEC,kCAAkC,EAAEC;EAAqB,CAAC,GACjErB,WAAW,CAAEG,aAAc,CAAC;EAE7B,OACCmB,aAAA,CAACvB,cAAc;IACdwB,SAAS,EAAGjB,cAAgB;IAC5BkB,SAAS,EAAC,iCAAiC;IAC3ChB,UAAU,EAAGA,UAAY;IACzBiB,aAAa,EAAGJ,oBAAsB;IACtCK,KAAK,EAAG7B,EAAE,CAAE,SAAU,CAAG;IACzBY,cAAc,EAAGA;EAAgB,GAE/B,CAAE;IAAEkB;EAAQ,CAAC,KACdpB,UAAU,IACTe,aAAA,CAAC9B,SAAS,QACT8B,aAAA;IAAKE,SAAS,EAAC;EAA6C,GAC3DF,aAAA,CAAC7B,iBAAiB;IACjB+B,SAAS,EAAC,2CAA2C;IACrDI,IAAI,EAAC,UAAU;IACfC,mBAAmB,EAAGxB,kBAAoB;IAC1CyB,WAAW,EACVR,aAAA,CAAAS,QAAA,QACGlC,EAAE,CAAE,oBAAqB,CAAC,EAC5ByB,aAAA,CAAC/B,IAAI;MAACyC,IAAI,EAAGpC;IAAU,CAAE,CACxB,CACF;IACDqC,SAAS,EAAGN;EAAS,CACrB,CACG,CACK,CAGE,CAAC;AAEnB"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { createElement } from "react";
|
|
2
|
-
/**
|
|
3
|
-
* WordPress dependencies
|
|
4
|
-
*/
|
|
5
|
-
import { __, isRTL } from '@wordpress/i18n';
|
|
6
|
-
import { useSelect, useDispatch } from '@wordpress/data';
|
|
7
|
-
import { BlockIcon, store as blockEditorStore } from '@wordpress/block-editor';
|
|
8
|
-
import { Button, VisuallyHidden, __experimentalHStack as HStack, __experimentalText as Text } from '@wordpress/components';
|
|
9
|
-
import { layout, chevronLeftSmall, chevronRightSmall } from '@wordpress/icons';
|
|
10
|
-
import { store as commandsStore } from '@wordpress/commands';
|
|
11
|
-
import { displayShortcut } from '@wordpress/keycodes';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Internal dependencies
|
|
15
|
-
*/
|
|
16
|
-
import { store as editPostStore } from '../../../store';
|
|
17
|
-
function DocumentActions() {
|
|
18
|
-
const {
|
|
19
|
-
template
|
|
20
|
-
} = useSelect(select => {
|
|
21
|
-
const {
|
|
22
|
-
getEditedPostTemplate
|
|
23
|
-
} = select(editPostStore);
|
|
24
|
-
return {
|
|
25
|
-
template: getEditedPostTemplate()
|
|
26
|
-
};
|
|
27
|
-
}, []);
|
|
28
|
-
const {
|
|
29
|
-
clearSelectedBlock
|
|
30
|
-
} = useDispatch(blockEditorStore);
|
|
31
|
-
const {
|
|
32
|
-
setIsEditingTemplate
|
|
33
|
-
} = useDispatch(editPostStore);
|
|
34
|
-
const {
|
|
35
|
-
open: openCommandCenter
|
|
36
|
-
} = useDispatch(commandsStore);
|
|
37
|
-
if (!template) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
let templateTitle = __('Default');
|
|
41
|
-
if (template?.title) {
|
|
42
|
-
templateTitle = template.title;
|
|
43
|
-
} else if (!!template) {
|
|
44
|
-
templateTitle = template.slug;
|
|
45
|
-
}
|
|
46
|
-
return createElement("div", {
|
|
47
|
-
className: "edit-post-document-actions"
|
|
48
|
-
}, createElement(Button, {
|
|
49
|
-
className: "edit-post-document-actions__back",
|
|
50
|
-
onClick: () => {
|
|
51
|
-
clearSelectedBlock();
|
|
52
|
-
setIsEditingTemplate(false);
|
|
53
|
-
},
|
|
54
|
-
icon: isRTL() ? chevronRightSmall : chevronLeftSmall
|
|
55
|
-
}, __('Back')), createElement(Button, {
|
|
56
|
-
className: "edit-post-document-actions__command",
|
|
57
|
-
onClick: () => openCommandCenter()
|
|
58
|
-
}, createElement(HStack, {
|
|
59
|
-
className: "edit-post-document-actions__title",
|
|
60
|
-
spacing: 1,
|
|
61
|
-
justify: "center"
|
|
62
|
-
}, createElement(BlockIcon, {
|
|
63
|
-
icon: layout
|
|
64
|
-
}), createElement(Text, {
|
|
65
|
-
size: "body",
|
|
66
|
-
as: "h1"
|
|
67
|
-
}, createElement(VisuallyHidden, {
|
|
68
|
-
as: "span"
|
|
69
|
-
}, __('Editing template: ')), templateTitle)), createElement("span", {
|
|
70
|
-
className: "edit-post-document-actions__shortcut"
|
|
71
|
-
}, displayShortcut.primary('k'))));
|
|
72
|
-
}
|
|
73
|
-
export default DocumentActions;
|
|
74
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["__","isRTL","useSelect","useDispatch","BlockIcon","store","blockEditorStore","Button","VisuallyHidden","__experimentalHStack","HStack","__experimentalText","Text","layout","chevronLeftSmall","chevronRightSmall","commandsStore","displayShortcut","editPostStore","DocumentActions","template","select","getEditedPostTemplate","clearSelectedBlock","setIsEditingTemplate","open","openCommandCenter","templateTitle","title","slug","createElement","className","onClick","icon","spacing","justify","size","as","primary"],"sources":["@wordpress/edit-post/src/components/header/document-actions/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, isRTL } from '@wordpress/i18n';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { BlockIcon, store as blockEditorStore } from '@wordpress/block-editor';\nimport {\n\tButton,\n\tVisuallyHidden,\n\t__experimentalHStack as HStack,\n\t__experimentalText as Text,\n} from '@wordpress/components';\nimport { layout, chevronLeftSmall, chevronRightSmall } from '@wordpress/icons';\nimport { store as commandsStore } from '@wordpress/commands';\nimport { displayShortcut } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { store as editPostStore } from '../../../store';\n\nfunction DocumentActions() {\n\tconst { template } = useSelect( ( select ) => {\n\t\tconst { getEditedPostTemplate } = select( editPostStore );\n\n\t\treturn {\n\t\t\ttemplate: getEditedPostTemplate(),\n\t\t};\n\t}, [] );\n\tconst { clearSelectedBlock } = useDispatch( blockEditorStore );\n\tconst { setIsEditingTemplate } = useDispatch( editPostStore );\n\tconst { open: openCommandCenter } = useDispatch( commandsStore );\n\n\tif ( ! template ) {\n\t\treturn null;\n\t}\n\n\tlet templateTitle = __( 'Default' );\n\tif ( template?.title ) {\n\t\ttemplateTitle = template.title;\n\t} else if ( !! template ) {\n\t\ttemplateTitle = template.slug;\n\t}\n\n\treturn (\n\t\t<div className=\"edit-post-document-actions\">\n\t\t\t<Button\n\t\t\t\tclassName=\"edit-post-document-actions__back\"\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tclearSelectedBlock();\n\t\t\t\t\tsetIsEditingTemplate( false );\n\t\t\t\t} }\n\t\t\t\ticon={ isRTL() ? chevronRightSmall : chevronLeftSmall }\n\t\t\t>\n\t\t\t\t{ __( 'Back' ) }\n\t\t\t</Button>\n\t\t\t<Button\n\t\t\t\tclassName=\"edit-post-document-actions__command\"\n\t\t\t\tonClick={ () => openCommandCenter() }\n\t\t\t>\n\t\t\t\t<HStack\n\t\t\t\t\tclassName=\"edit-post-document-actions__title\"\n\t\t\t\t\tspacing={ 1 }\n\t\t\t\t\tjustify=\"center\"\n\t\t\t\t>\n\t\t\t\t\t<BlockIcon icon={ layout } />\n\t\t\t\t\t<Text size=\"body\" as=\"h1\">\n\t\t\t\t\t\t<VisuallyHidden as=\"span\">\n\t\t\t\t\t\t\t{ __( 'Editing template: ' ) }\n\t\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t\t{ templateTitle }\n\t\t\t\t\t</Text>\n\t\t\t\t</HStack>\n\t\t\t\t<span className=\"edit-post-document-actions__shortcut\">\n\t\t\t\t\t{ displayShortcut.primary( 'k' ) }\n\t\t\t\t</span>\n\t\t\t</Button>\n\t\t</div>\n\t);\n}\n\nexport default Document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AAGP,QAAQ,CAACS,IAAI;EAC9B;EAEA,OACCC,aAAA;IAAKC,SAAS,EAAC;EAA4B,GAC1CD,aAAA,CAACvB,MAAM;IACNwB,SAAS,EAAC,kCAAkC;IAC5CC,OAAO,EAAGA,CAAA,KAAM;MACfT,kBAAkB,CAAC,CAAC;MACpBC,oBAAoB,CAAE,KAAM,CAAC;IAC9B,CAAG;IACHS,IAAI,EAAGhC,KAAK,CAAC,CAAC,GAAGc,iBAAiB,GAAGD;EAAkB,GAErDd,EAAE,CAAE,MAAO,CACN,CAAC,EACT8B,aAAA,CAACvB,MAAM;IACNwB,SAAS,EAAC,qCAAqC;IAC/CC,OAAO,EAAGA,CAAA,KAAMN,iBAAiB,CAAC;EAAG,GAErCI,aAAA,CAACpB,MAAM;IACNqB,SAAS,EAAC,mCAAmC;IAC7CG,OAAO,EAAG,CAAG;IACbC,OAAO,EAAC;EAAQ,GAEhBL,aAAA,CAAC1B,SAAS;IAAC6B,IAAI,EAAGpB;EAAQ,CAAE,CAAC,EAC7BiB,aAAA,CAAClB,IAAI;IAACwB,IAAI,EAAC,MAAM;IAACC,EAAE,EAAC;EAAI,GACxBP,aAAA,CAACtB,cAAc;IAAC6B,EAAE,EAAC;EAAM,GACtBrC,EAAE,CAAE,oBAAqB,CACZ,CAAC,EACf2B,aACG,CACC,CAAC,EACTG,aAAA;IAAMC,SAAS,EAAC;EAAsC,GACnDd,eAAe,CAACqB,OAAO,CAAE,GAAI,CAC1B,CACC,CACJ,CAAC;AAER;AAEA,eAAenB,eAAe"}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { createElement } from "react";
|
|
2
|
-
/**
|
|
3
|
-
* WordPress dependencies
|
|
4
|
-
*/
|
|
5
|
-
import { useSelect, useDispatch } from '@wordpress/data';
|
|
6
|
-
import { store as editorStore } from '@wordpress/editor';
|
|
7
|
-
import { useState } from '@wordpress/element';
|
|
8
|
-
import { serialize, createBlock } from '@wordpress/blocks';
|
|
9
|
-
import { Modal, TextControl, Button, __experimentalHStack as HStack, __experimentalVStack as VStack } from '@wordpress/components';
|
|
10
|
-
import { __ } from '@wordpress/i18n';
|
|
11
|
-
import { cleanForSlug } from '@wordpress/url';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Internal dependencies
|
|
15
|
-
*/
|
|
16
|
-
import { store as editPostStore } from '../../../store';
|
|
17
|
-
const DEFAULT_TITLE = __('Custom Template');
|
|
18
|
-
export default function PostTemplateCreateModal({
|
|
19
|
-
onClose
|
|
20
|
-
}) {
|
|
21
|
-
const defaultBlockTemplate = useSelect(select => select(editorStore).getEditorSettings().defaultBlockTemplate, []);
|
|
22
|
-
const {
|
|
23
|
-
__unstableCreateTemplate,
|
|
24
|
-
__unstableSwitchToTemplateMode
|
|
25
|
-
} = useDispatch(editPostStore);
|
|
26
|
-
const [title, setTitle] = useState('');
|
|
27
|
-
const [isBusy, setIsBusy] = useState(false);
|
|
28
|
-
const cancel = () => {
|
|
29
|
-
setTitle('');
|
|
30
|
-
onClose();
|
|
31
|
-
};
|
|
32
|
-
const submit = async event => {
|
|
33
|
-
event.preventDefault();
|
|
34
|
-
if (isBusy) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
setIsBusy(true);
|
|
38
|
-
const newTemplateContent = defaultBlockTemplate !== null && defaultBlockTemplate !== void 0 ? defaultBlockTemplate : serialize([createBlock('core/group', {
|
|
39
|
-
tagName: 'header',
|
|
40
|
-
layout: {
|
|
41
|
-
inherit: true
|
|
42
|
-
}
|
|
43
|
-
}, [createBlock('core/site-title'), createBlock('core/site-tagline')]), createBlock('core/separator'), createBlock('core/group', {
|
|
44
|
-
tagName: 'main'
|
|
45
|
-
}, [createBlock('core/group', {
|
|
46
|
-
layout: {
|
|
47
|
-
inherit: true
|
|
48
|
-
}
|
|
49
|
-
}, [createBlock('core/post-title')]), createBlock('core/post-content', {
|
|
50
|
-
layout: {
|
|
51
|
-
inherit: true
|
|
52
|
-
}
|
|
53
|
-
})])]);
|
|
54
|
-
await __unstableCreateTemplate({
|
|
55
|
-
slug: cleanForSlug(title || DEFAULT_TITLE),
|
|
56
|
-
content: newTemplateContent,
|
|
57
|
-
title: title || DEFAULT_TITLE
|
|
58
|
-
});
|
|
59
|
-
setIsBusy(false);
|
|
60
|
-
cancel();
|
|
61
|
-
__unstableSwitchToTemplateMode(true);
|
|
62
|
-
};
|
|
63
|
-
return createElement(Modal, {
|
|
64
|
-
title: __('Create custom template'),
|
|
65
|
-
onRequestClose: cancel,
|
|
66
|
-
className: "edit-post-post-template__create-modal"
|
|
67
|
-
}, createElement("form", {
|
|
68
|
-
className: "edit-post-post-template__create-form",
|
|
69
|
-
onSubmit: submit
|
|
70
|
-
}, createElement(VStack, {
|
|
71
|
-
spacing: "3"
|
|
72
|
-
}, createElement(TextControl, {
|
|
73
|
-
__nextHasNoMarginBottom: true,
|
|
74
|
-
label: __('Name'),
|
|
75
|
-
value: title,
|
|
76
|
-
onChange: setTitle,
|
|
77
|
-
placeholder: DEFAULT_TITLE,
|
|
78
|
-
disabled: isBusy,
|
|
79
|
-
help: __('Describe the template, e.g. "Post with sidebar". A custom template can be manually applied to any post or page.')
|
|
80
|
-
}), createElement(HStack, {
|
|
81
|
-
justify: "right"
|
|
82
|
-
}, createElement(Button, {
|
|
83
|
-
variant: "tertiary",
|
|
84
|
-
onClick: cancel
|
|
85
|
-
}, __('Cancel')), createElement(Button, {
|
|
86
|
-
variant: "primary",
|
|
87
|
-
type: "submit",
|
|
88
|
-
isBusy: isBusy,
|
|
89
|
-
"aria-disabled": isBusy
|
|
90
|
-
}, __('Create'))))));
|
|
91
|
-
}
|
|
92
|
-
//# sourceMappingURL=create-modal.js.map
|