@wordpress/edit-post 6.8.0 → 6.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/build/components/header/header-toolbar/index.js +7 -6
- package/build/components/header/header-toolbar/index.js.map +1 -1
- package/build/components/header/template-title/edit-template-title.js +11 -2
- package/build/components/header/template-title/edit-template-title.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/config.js +12 -0
- package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/index.js +1 -3
- package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build/components/preferences-modal/index.js +3 -26
- package/build/components/preferences-modal/index.js.map +1 -1
- package/build/components/sidebar/plugin-post-status-info/index.js +2 -2
- package/build/components/sidebar/plugin-post-status-info/index.js.map +1 -1
- package/build/components/sidebar/post-format/index.js +3 -1
- package/build/components/sidebar/post-format/index.js.map +1 -1
- package/build/components/sidebar/post-schedule/index.js +28 -12
- package/build/components/sidebar/post-schedule/index.js.map +1 -1
- package/build/components/sidebar/post-slug/index.js +3 -1
- package/build/components/sidebar/post-slug/index.js.map +1 -1
- package/build/components/sidebar/post-status/index.js +6 -2
- package/build/components/sidebar/post-status/index.js.map +1 -1
- package/build/components/sidebar/post-template/create-modal.js +116 -0
- package/build/components/sidebar/post-template/create-modal.js.map +1 -0
- package/build/components/sidebar/post-template/form.js +123 -0
- package/build/components/sidebar/post-template/form.js.map +1 -0
- package/build/components/sidebar/post-template/index.js +128 -0
- package/build/components/sidebar/post-template/index.js.map +1 -0
- package/build/components/sidebar/post-url/index.js +68 -0
- package/build/components/sidebar/post-url/index.js.map +1 -0
- package/build/components/sidebar/post-visibility/index.js +21 -6
- package/build/components/sidebar/post-visibility/index.js.map +1 -1
- package/build/components/sidebar/settings-sidebar/index.js +2 -6
- package/build/components/sidebar/settings-sidebar/index.js.map +1 -1
- package/build/components/start-page-options/index.js +31 -13
- package/build/components/start-page-options/index.js.map +1 -1
- package/build/components/visual-editor/index.js +4 -2
- package/build/components/visual-editor/index.js.map +1 -1
- package/build/editor.js +8 -3
- package/build/editor.js.map +1 -1
- package/build/editor.native.js +1 -1
- package/build/editor.native.js.map +1 -1
- package/build/store/selectors.js +8 -8
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/header/header-toolbar/index.js +8 -6
- package/build-module/components/header/header-toolbar/index.js.map +1 -1
- package/build-module/components/header/template-title/edit-template-title.js +12 -2
- package/build-module/components/header/template-title/edit-template-title.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/config.js +12 -0
- package/build-module/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.js +1 -2
- package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build-module/components/preferences-modal/index.js +3 -25
- package/build-module/components/preferences-modal/index.js.map +1 -1
- package/build-module/components/sidebar/plugin-post-status-info/index.js +2 -2
- package/build-module/components/sidebar/plugin-post-status-info/index.js.map +1 -1
- package/build-module/components/sidebar/post-format/index.js +3 -1
- package/build-module/components/sidebar/post-format/index.js.map +1 -1
- package/build-module/components/sidebar/post-schedule/index.js +32 -13
- package/build-module/components/sidebar/post-schedule/index.js.map +1 -1
- package/build-module/components/sidebar/post-slug/index.js +3 -1
- package/build-module/components/sidebar/post-slug/index.js.map +1 -1
- package/build-module/components/sidebar/post-status/index.js +4 -2
- package/build-module/components/sidebar/post-status/index.js.map +1 -1
- package/build-module/components/sidebar/post-template/create-modal.js +104 -0
- package/build-module/components/sidebar/post-template/create-modal.js.map +1 -0
- package/build-module/components/sidebar/post-template/form.js +106 -0
- package/build-module/components/sidebar/post-template/form.js.map +1 -0
- package/build-module/components/sidebar/post-template/index.js +114 -0
- package/build-module/components/sidebar/post-template/index.js.map +1 -0
- package/build-module/components/sidebar/post-url/index.js +59 -0
- package/build-module/components/sidebar/post-url/index.js.map +1 -0
- package/build-module/components/sidebar/post-visibility/index.js +24 -8
- package/build-module/components/sidebar/post-visibility/index.js.map +1 -1
- package/build-module/components/sidebar/settings-sidebar/index.js +2 -4
- package/build-module/components/sidebar/settings-sidebar/index.js.map +1 -1
- package/build-module/components/start-page-options/index.js +32 -14
- package/build-module/components/start-page-options/index.js.map +1 -1
- package/build-module/components/visual-editor/index.js +4 -2
- package/build-module/components/visual-editor/index.js.map +1 -1
- package/build-module/editor.js +9 -4
- package/build-module/editor.js.map +1 -1
- package/build-module/editor.native.js +2 -2
- package/build-module/editor.native.js.map +1 -1
- package/build-module/store/selectors.js +8 -7
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +82 -91
- package/build-style/style.css +81 -94
- package/package.json +27 -27
- package/src/components/header/header-toolbar/index.js +10 -10
- package/src/components/header/header-toolbar/style.scss +2 -5
- package/src/components/header/style.scss +0 -6
- package/src/components/header/template-title/edit-template-title.js +11 -1
- package/src/components/keyboard-shortcut-help-modal/config.js +8 -0
- package/src/components/keyboard-shortcut-help-modal/index.js +1 -2
- package/src/components/keyboard-shortcut-help-modal/style.scss +0 -5
- package/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap +14 -0
- package/src/components/preferences-modal/index.js +5 -23
- package/src/components/preferences-modal/test/index.js +3 -3
- package/src/components/sidebar/plugin-post-status-info/index.js +2 -2
- package/src/components/sidebar/post-author/style.scss +4 -10
- package/src/components/sidebar/post-format/index.js +1 -1
- package/src/components/sidebar/post-format/style.scss +5 -0
- package/src/components/sidebar/post-schedule/index.js +27 -16
- package/src/components/sidebar/post-schedule/style.scss +16 -3
- package/src/components/sidebar/post-slug/index.js +1 -1
- package/src/components/sidebar/post-slug/style.scss +4 -3
- package/src/components/sidebar/post-status/index.js +6 -2
- package/src/components/sidebar/post-template/create-modal.js +146 -0
- package/src/components/sidebar/post-template/form.js +143 -0
- package/src/components/sidebar/post-template/index.js +106 -0
- package/src/components/sidebar/post-template/style.scss +36 -0
- package/src/components/sidebar/post-url/index.js +51 -0
- package/src/components/sidebar/post-url/style.scss +23 -0
- package/src/components/sidebar/post-visibility/index.js +22 -8
- package/src/components/sidebar/post-visibility/style.scss +4 -4
- package/src/components/sidebar/settings-sidebar/index.js +1 -5
- package/src/components/sidebar/template/style.scss +0 -8
- package/src/components/start-page-options/index.js +46 -22
- package/src/components/start-page-options/style.scss +0 -9
- package/src/components/visual-editor/index.js +2 -1
- package/src/editor.js +8 -4
- package/src/editor.native.js +2 -2
- package/src/store/selectors.js +5 -8
- package/src/style.scss +3 -2
- package/src/test/editor.native.js +1 -3
- package/build/components/sidebar/post-link/index.js +0 -182
- package/build/components/sidebar/post-link/index.js.map +0 -1
- package/build/components/sidebar/template/actions.js +0 -172
- package/build/components/sidebar/template/actions.js.map +0 -1
- package/build/components/sidebar/template/index.js +0 -164
- package/build/components/sidebar/template/index.js.map +0 -1
- package/build-module/components/sidebar/post-link/index.js +0 -165
- package/build-module/components/sidebar/post-link/index.js.map +0 -1
- package/build-module/components/sidebar/template/actions.js +0 -158
- package/build-module/components/sidebar/template/actions.js.map +0 -1
- package/build-module/components/sidebar/template/index.js +0 -145
- package/build-module/components/sidebar/template/index.js.map +0 -1
- package/src/components/sidebar/post-link/index.js +0 -179
- package/src/components/sidebar/post-link/style.scss +0 -20
- package/src/components/sidebar/template/actions.js +0 -206
- package/src/components/sidebar/template/index.js +0 -160
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/template/actions.js"],"names":["PostTemplateActions","isPostsPage","isModalOpen","setIsModalOpen","isBusy","setIsBusy","title","setTitle","template","supportsTemplateMode","defaultTemplate","select","getCurrentPostType","getEditorSettings","editorStore","getPostType","coreStore","getEditedPostTemplate","editPostStore","isViewable","viewable","_supportsTemplateMode","defaultBlockTemplate","__unstableCreateTemplate","__unstableSwitchToTemplateMode","defaultTitle","onCreateTemplate","event","preventDefault","newTemplateContent","tagName","layout","inherit","slug","content","toLowerCase"],"mappings":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C,IAAA,OAAO,EAAC,UAFT;AAGC,IAAA,QAAQ,EAAG;AAHZ,KAKC,4BAAC,oBAAD,QACC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,UADT;AAEC,IAAA,OAAO,EAAG,MAAM;AACfD,MAAAA,cAAc,CAAE,KAAF,CAAd;AACAI,MAAAA,QAAQ,CAAE,EAAF,CAAR;AACA;AALF,KAOG,cAAI,QAAJ,CAPH,CADD,CALD,EAgBC,4BAAC,oBAAD,QACC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,IAAI,EAAC,QAFN;AAGC,IAAA,MAAM,EAAGH,MAHV;AAIC,qBAAgBA;AAJjB,KAMG,cAAI,QAAJ,CANH,CADD,CAhBD,CAhBD,CATD,CA7BF,CADD;AAuFA;;eAEcJ,mB","sourcesContent":["/**\n * External dependencies\n */\nimport { kebabCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport {\n\tButton,\n\tModal,\n\tTextControl,\n\tFlex,\n\tFlexItem,\n} from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\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 { createBlock, serialize } from '@wordpress/blocks';\n\nfunction PostTemplateActions( { isPostsPage } ) {\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst [ isBusy, setIsBusy ] = useState( false );\n\tconst [ title, setTitle ] = useState( '' );\n\tconst { template, supportsTemplateMode, defaultTemplate } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCurrentPostType, getEditorSettings } =\n\t\t\t\tselect( editorStore );\n\t\t\tconst { getPostType } = select( coreStore );\n\t\t\tconst { getEditedPostTemplate } = select( editPostStore );\n\n\t\t\tconst isViewable =\n\t\t\t\tgetPostType( getCurrentPostType() )?.viewable ?? false;\n\t\t\tconst _supportsTemplateMode =\n\t\t\t\tgetEditorSettings().supportsTemplateMode && isViewable;\n\n\t\t\treturn {\n\t\t\t\ttemplate: _supportsTemplateMode && getEditedPostTemplate(),\n\t\t\t\tsupportsTemplateMode: _supportsTemplateMode,\n\t\t\t\tdefaultTemplate: getEditorSettings().defaultBlockTemplate,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\tconst { __unstableCreateTemplate, __unstableSwitchToTemplateMode } =\n\t\tuseDispatch( editPostStore );\n\n\tif ( ! supportsTemplateMode ) {\n\t\treturn null;\n\t}\n\n\tconst defaultTitle = __( 'Custom Template' );\n\n\tasync function onCreateTemplate( event ) {\n\t\tevent.preventDefault();\n\n\t\tif ( isBusy ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsBusy( true );\n\n\t\tconst newTemplateContent =\n\t\t\tdefaultTemplate ??\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: 'wp-custom-template-' + kebabCase( title || defaultTitle ),\n\t\t\tcontent: newTemplateContent,\n\t\t\ttitle: title || defaultTitle,\n\t\t} );\n\n\t\tsetIsBusy( false );\n\t\tsetIsModalOpen( false );\n\n\t\t__unstableSwitchToTemplateMode( true );\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<div className=\"edit-post-template__actions\">\n\t\t\t\t{ !! template && (\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\tlabel={ sprintf(\n\t\t\t\t\t\t\t// Translators: 1: The title or the slug of the currently selected template.\n\t\t\t\t\t\t\t__( 'Edit template: %s' ),\n\t\t\t\t\t\t\ttemplate?.title.toLowerCase() ?? template.slug\n\t\t\t\t\t\t) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Edit' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\t\t\t\t{ ! isPostsPage && (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"link\"\n\t\t\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t\t\t\tlabel={ _x( 'New template', 'action' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/* translators: button to create a new template */\n\t\t\t\t\t\t\t_x( 'New', 'action' )\n\t\t\t\t\t\t}\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Create custom template' ) }\n\t\t\t\t\tcloseLabel={ __( 'Close' ) }\n\t\t\t\t\tonRequestClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t} }\n\t\t\t\t\toverlayClassName=\"edit-post-template__modal\"\n\t\t\t\t>\n\t\t\t\t\t<form onSubmit={ onCreateTemplate }>\n\t\t\t\t\t\t<Flex align=\"flex-start\" gap={ 8 }>\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\t\t\t\tplaceholder={ defaultTitle }\n\t\t\t\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t\t'Describe the purpose of the template, e.g. \"Full Width\". Custom templates can be applied to any post or page.'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t</Flex>\n\n\t\t\t\t\t\t<Flex\n\t\t\t\t\t\t\tclassName=\"edit-post-template__modal-actions\"\n\t\t\t\t\t\t\tjustify=\"flex-end\"\n\t\t\t\t\t\t\texpanded={ false }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\t\t\t\taria-disabled={ isBusy }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t</Flex>\n\t\t\t\t\t</form>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default PostTemplateActions;\n"]}
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.TemplatePanel = TemplatePanel;
|
|
9
|
-
exports.default = void 0;
|
|
10
|
-
|
|
11
|
-
var _element = require("@wordpress/element");
|
|
12
|
-
|
|
13
|
-
var _lodash = require("lodash");
|
|
14
|
-
|
|
15
|
-
var _i18n = require("@wordpress/i18n");
|
|
16
|
-
|
|
17
|
-
var _components = require("@wordpress/components");
|
|
18
|
-
|
|
19
|
-
var _editor = require("@wordpress/editor");
|
|
20
|
-
|
|
21
|
-
var _data = require("@wordpress/data");
|
|
22
|
-
|
|
23
|
-
var _coreData = require("@wordpress/core-data");
|
|
24
|
-
|
|
25
|
-
var _actions = _interopRequireDefault(require("./actions"));
|
|
26
|
-
|
|
27
|
-
var _store = require("../../../store");
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* External dependencies
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* WordPress dependencies
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Internal dependencies
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Module Constants
|
|
43
|
-
*/
|
|
44
|
-
const PANEL_NAME = 'template';
|
|
45
|
-
|
|
46
|
-
function TemplatePanel() {
|
|
47
|
-
const {
|
|
48
|
-
isEnabled,
|
|
49
|
-
isOpened,
|
|
50
|
-
isPostsPage,
|
|
51
|
-
selectedTemplate,
|
|
52
|
-
availableTemplates,
|
|
53
|
-
fetchedTemplates,
|
|
54
|
-
isViewable,
|
|
55
|
-
template,
|
|
56
|
-
supportsTemplateMode,
|
|
57
|
-
canUserCreate
|
|
58
|
-
} = (0, _data.useSelect)(select => {
|
|
59
|
-
var _getPostType$viewable, _getPostType;
|
|
60
|
-
|
|
61
|
-
const {
|
|
62
|
-
isEditorPanelEnabled,
|
|
63
|
-
isEditorPanelOpened,
|
|
64
|
-
getEditedPostTemplate
|
|
65
|
-
} = select(_store.store);
|
|
66
|
-
const {
|
|
67
|
-
getEditedPostAttribute,
|
|
68
|
-
getEditorSettings,
|
|
69
|
-
getCurrentPostId,
|
|
70
|
-
getCurrentPostType
|
|
71
|
-
} = select(_editor.store);
|
|
72
|
-
const {
|
|
73
|
-
getPostType,
|
|
74
|
-
getEntityRecord,
|
|
75
|
-
getEntityRecords,
|
|
76
|
-
canUser
|
|
77
|
-
} = select(_coreData.store);
|
|
78
|
-
const currentPostId = getCurrentPostId();
|
|
79
|
-
const currentPostType = getCurrentPostType();
|
|
80
|
-
const settings = getEntityRecord('root', 'site');
|
|
81
|
-
|
|
82
|
-
const _isViewable = (_getPostType$viewable = (_getPostType = getPostType(currentPostType)) === null || _getPostType === void 0 ? void 0 : _getPostType.viewable) !== null && _getPostType$viewable !== void 0 ? _getPostType$viewable : false;
|
|
83
|
-
|
|
84
|
-
const _supportsTemplateMode = select(_editor.store).getEditorSettings().supportsTemplateMode && _isViewable;
|
|
85
|
-
|
|
86
|
-
const templateRecords = getEntityRecords('postType', 'wp_template', {
|
|
87
|
-
post_type: currentPostType,
|
|
88
|
-
per_page: -1
|
|
89
|
-
});
|
|
90
|
-
return {
|
|
91
|
-
isEnabled: isEditorPanelEnabled(PANEL_NAME),
|
|
92
|
-
isOpened: isEditorPanelOpened(PANEL_NAME),
|
|
93
|
-
isPostsPage: currentPostId === (settings === null || settings === void 0 ? void 0 : settings.page_for_posts),
|
|
94
|
-
selectedTemplate: getEditedPostAttribute('template'),
|
|
95
|
-
availableTemplates: getEditorSettings().availableTemplates,
|
|
96
|
-
fetchedTemplates: templateRecords,
|
|
97
|
-
template: _supportsTemplateMode && getEditedPostTemplate(),
|
|
98
|
-
isViewable: _isViewable,
|
|
99
|
-
supportsTemplateMode: _supportsTemplateMode,
|
|
100
|
-
canUserCreate: canUser('create', 'templates')
|
|
101
|
-
};
|
|
102
|
-
}, []);
|
|
103
|
-
const templates = (0, _element.useMemo)(() => {
|
|
104
|
-
return { ...availableTemplates,
|
|
105
|
-
...(0, _lodash.fromPairs)((fetchedTemplates !== null && fetchedTemplates !== void 0 ? fetchedTemplates : []).map(_ref => {
|
|
106
|
-
let {
|
|
107
|
-
slug,
|
|
108
|
-
title
|
|
109
|
-
} = _ref;
|
|
110
|
-
return [slug, title.rendered];
|
|
111
|
-
}))
|
|
112
|
-
};
|
|
113
|
-
}, [availableTemplates, fetchedTemplates]);
|
|
114
|
-
const {
|
|
115
|
-
toggleEditorPanelOpened
|
|
116
|
-
} = (0, _data.useDispatch)(_store.store);
|
|
117
|
-
const {
|
|
118
|
-
editPost
|
|
119
|
-
} = (0, _data.useDispatch)(_editor.store);
|
|
120
|
-
|
|
121
|
-
if (!isEnabled || !isViewable || (0, _lodash.isEmpty)(availableTemplates) && (!supportsTemplateMode || !canUserCreate)) {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const onTogglePanel = (0, _lodash.partial)(toggleEditorPanelOpened, PANEL_NAME);
|
|
126
|
-
let panelTitle = (0, _i18n.__)('Template');
|
|
127
|
-
|
|
128
|
-
if (!!template) {
|
|
129
|
-
var _template$title;
|
|
130
|
-
|
|
131
|
-
panelTitle = (0, _i18n.sprintf)(
|
|
132
|
-
/* translators: %s: template title */
|
|
133
|
-
(0, _i18n.__)('Template: %s'), (_template$title = template === null || template === void 0 ? void 0 : template.title) !== null && _template$title !== void 0 ? _template$title : template.slug);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return (0, _element.createElement)(_components.PanelBody, {
|
|
137
|
-
title: panelTitle,
|
|
138
|
-
opened: isOpened,
|
|
139
|
-
onToggle: onTogglePanel
|
|
140
|
-
}, isPostsPage ? (0, _element.createElement)(_components.Notice, {
|
|
141
|
-
className: "edit-post-template__notice",
|
|
142
|
-
status: "warning",
|
|
143
|
-
isDismissible: false
|
|
144
|
-
}, (0, _i18n.__)('The posts page template cannot be changed.')) : (0, _element.createElement)(_components.SelectControl, {
|
|
145
|
-
hideLabelFromVision: true,
|
|
146
|
-
label: (0, _i18n.__)('Template:'),
|
|
147
|
-
value: Object.keys(templates).includes(selectedTemplate) ? selectedTemplate : '',
|
|
148
|
-
onChange: templateSlug => {
|
|
149
|
-
editPost({
|
|
150
|
-
template: templateSlug || ''
|
|
151
|
-
});
|
|
152
|
-
},
|
|
153
|
-
options: (0, _lodash.map)(templates, (templateName, templateSlug) => ({
|
|
154
|
-
value: templateSlug,
|
|
155
|
-
label: templateName
|
|
156
|
-
}))
|
|
157
|
-
}), canUserCreate && (0, _element.createElement)(_actions.default, {
|
|
158
|
-
isPostsPage: isPostsPage
|
|
159
|
-
}));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
var _default = TemplatePanel;
|
|
163
|
-
exports.default = _default;
|
|
164
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/template/index.js"],"names":["PANEL_NAME","TemplatePanel","isEnabled","isOpened","isPostsPage","selectedTemplate","availableTemplates","fetchedTemplates","isViewable","template","supportsTemplateMode","canUserCreate","select","isEditorPanelEnabled","isEditorPanelOpened","getEditedPostTemplate","editPostStore","getEditedPostAttribute","getEditorSettings","getCurrentPostId","getCurrentPostType","editorStore","getPostType","getEntityRecord","getEntityRecords","canUser","coreStore","currentPostId","currentPostType","settings","_isViewable","viewable","_supportsTemplateMode","templateRecords","post_type","per_page","page_for_posts","templates","map","slug","title","rendered","toggleEditorPanelOpened","editPost","onTogglePanel","panelTitle","Object","keys","includes","templateSlug","templateName","value","label"],"mappings":";;;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAnBA;AACA;AACA;;AAGA;AACA;AACA;;AAQA;AACA;AACA;;AAIA;AACA;AACA;AACA,MAAMA,UAAU,GAAG,UAAnB;;AAEO,SAASC,aAAT,GAAyB;AAC/B,QAAM;AACLC,IAAAA,SADK;AAELC,IAAAA,QAFK;AAGLC,IAAAA,WAHK;AAILC,IAAAA,gBAJK;AAKLC,IAAAA,kBALK;AAMLC,IAAAA,gBANK;AAOLC,IAAAA,UAPK;AAQLC,IAAAA,QARK;AASLC,IAAAA,oBATK;AAULC,IAAAA;AAVK,MAWF,qBAAaC,MAAF,IAAc;AAAA;;AAC5B,UAAM;AACLC,MAAAA,oBADK;AAELC,MAAAA,mBAFK;AAGLC,MAAAA;AAHK,QAIFH,MAAM,CAAEI,YAAF,CAJV;AAKA,UAAM;AACLC,MAAAA,sBADK;AAELC,MAAAA,iBAFK;AAGLC,MAAAA,gBAHK;AAILC,MAAAA;AAJK,QAKFR,MAAM,CAAES,aAAF,CALV;AAMA,UAAM;AAAEC,MAAAA,WAAF;AAAeC,MAAAA,eAAf;AAAgCC,MAAAA,gBAAhC;AAAkDC,MAAAA;AAAlD,QACLb,MAAM,CAAEc,eAAF,CADP;AAGA,UAAMC,aAAa,GAAGR,gBAAgB,EAAtC;AACA,UAAMS,eAAe,GAAGR,kBAAkB,EAA1C;AACA,UAAMS,QAAQ,GAAGN,eAAe,CAAE,MAAF,EAAU,MAAV,CAAhC;;AACA,UAAMO,WAAW,4CAAGR,WAAW,CAAEM,eAAF,CAAd,iDAAG,aAAgCG,QAAnC,yEAA+C,KAAhE;;AACA,UAAMC,qBAAqB,GAC1BpB,M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S,EAET,CAAEa,YAAF,EAAgBD,YAAhB,MAAoC;AACnCE,MAAAA,KAAK,EAAEF,YAD4B;AAEnCG,MAAAA,KAAK,EAAEF;AAF4B,KAApC,CAFS;AAbX,IAdF,EAoCGvC,aAAa,IACd,4BAAC,gBAAD;AAAqB,IAAA,WAAW,EAAGP;AAAnC,IArCF,CADD;AA0CA;;eAEcH,a","sourcesContent":["/**\n * External dependencies\n */\nimport { partial, isEmpty, map, fromPairs } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { Notice, PanelBody, SelectControl } from '@wordpress/components';\nimport { store as editorStore } from '@wordpress/editor';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport PostTemplateActions from './actions';\nimport { store as editPostStore } from '../../../store';\n\n/**\n * Module Constants\n */\nconst PANEL_NAME = 'template';\n\nexport function TemplatePanel() {\n\tconst {\n\t\tisEnabled,\n\t\tisOpened,\n\t\tisPostsPage,\n\t\tselectedTemplate,\n\t\tavailableTemplates,\n\t\tfetchedTemplates,\n\t\tisViewable,\n\t\ttemplate,\n\t\tsupportsTemplateMode,\n\t\tcanUserCreate,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tisEditorPanelEnabled,\n\t\t\tisEditorPanelOpened,\n\t\t\tgetEditedPostTemplate,\n\t\t} = select( editPostStore );\n\t\tconst {\n\t\t\tgetEditedPostAttribute,\n\t\t\tgetEditorSettings,\n\t\t\tgetCurrentPostId,\n\t\t\tgetCurrentPostType,\n\t\t} = select( editorStore );\n\t\tconst { getPostType, getEntityRecord, getEntityRecords, canUser } =\n\t\t\tselect( coreStore );\n\n\t\tconst currentPostId = getCurrentPostId();\n\t\tconst currentPostType = getCurrentPostType();\n\t\tconst settings = getEntityRecord( 'root', 'site' );\n\t\tconst _isViewable = getPostType( currentPostType )?.viewable ?? false;\n\t\tconst _supportsTemplateMode =\n\t\t\tselect( editorStore ).getEditorSettings().supportsTemplateMode &&\n\t\t\t_isViewable;\n\n\t\tconst templateRecords = getEntityRecords( 'postType', 'wp_template', {\n\t\t\tpost_type: currentPostType,\n\t\t\tper_page: -1,\n\t\t} );\n\n\t\treturn {\n\t\t\tisEnabled: isEditorPanelEnabled( PANEL_NAME ),\n\t\t\tisOpened: isEditorPanelOpened( PANEL_NAME ),\n\t\t\tisPostsPage: currentPostId === settings?.page_for_posts,\n\t\t\tselectedTemplate: getEditedPostAttribute( 'template' ),\n\t\t\tavailableTemplates: getEditorSettings().availableTemplates,\n\t\t\tfetchedTemplates: templateRecords,\n\t\t\ttemplate: _supportsTemplateMode && getEditedPostTemplate(),\n\t\t\tisViewable: _isViewable,\n\t\t\tsupportsTemplateMode: _supportsTemplateMode,\n\t\t\tcanUserCreate: canUser( 'create', 'templates' ),\n\t\t};\n\t}, [] );\n\n\tconst templates = useMemo( () => {\n\t\treturn {\n\t\t\t...availableTemplates,\n\t\t\t...fromPairs(\n\t\t\t\t( fetchedTemplates ?? [] ).map( ( { slug, title } ) => [\n\t\t\t\t\tslug,\n\t\t\t\t\ttitle.rendered,\n\t\t\t\t] )\n\t\t\t),\n\t\t};\n\t}, [ availableTemplates, fetchedTemplates ] );\n\n\tconst { toggleEditorPanelOpened } = useDispatch( editPostStore );\n\tconst { editPost } = useDispatch( editorStore );\n\n\tif (\n\t\t! isEnabled ||\n\t\t! isViewable ||\n\t\t( isEmpty( availableTemplates ) &&\n\t\t\t( ! supportsTemplateMode || ! canUserCreate ) )\n\t) {\n\t\treturn null;\n\t}\n\n\tconst onTogglePanel = partial( toggleEditorPanelOpened, PANEL_NAME );\n\n\tlet panelTitle = __( 'Template' );\n\tif ( !! template ) {\n\t\tpanelTitle = sprintf(\n\t\t\t/* translators: %s: template title */\n\t\t\t__( 'Template: %s' ),\n\t\t\ttemplate?.title ?? template.slug\n\t\t);\n\t}\n\n\treturn (\n\t\t<PanelBody\n\t\t\ttitle={ panelTitle }\n\t\t\topened={ isOpened }\n\t\t\tonToggle={ onTogglePanel }\n\t\t>\n\t\t\t{ isPostsPage ? (\n\t\t\t\t<Notice\n\t\t\t\t\tclassName=\"edit-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\thideLabelFromVision\n\t\t\t\t\tlabel={ __( 'Template:' ) }\n\t\t\t\t\tvalue={\n\t\t\t\t\t\tObject.keys( templates ).includes( selectedTemplate )\n\t\t\t\t\t\t\t? selectedTemplate\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\t}\n\t\t\t\t\tonChange={ ( templateSlug ) => {\n\t\t\t\t\t\teditPost( {\n\t\t\t\t\t\t\ttemplate: templateSlug || '',\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\toptions={ map(\n\t\t\t\t\t\ttemplates,\n\t\t\t\t\t\t( templateName, templateSlug ) => ( {\n\t\t\t\t\t\t\tvalue: templateSlug,\n\t\t\t\t\t\t\tlabel: templateName,\n\t\t\t\t\t\t} )\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ canUserCreate && (\n\t\t\t\t<PostTemplateActions isPostsPage={ isPostsPage } />\n\t\t\t) }\n\t\t</PanelBody>\n\t);\n}\n\nexport default TemplatePanel;\n"]}
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { createElement, Fragment } from "@wordpress/element";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* External dependencies
|
|
5
|
-
*/
|
|
6
|
-
import { get } from 'lodash';
|
|
7
|
-
/**
|
|
8
|
-
* WordPress dependencies
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { __ } from '@wordpress/i18n';
|
|
12
|
-
import { PanelBody, TextControl, ExternalLink } from '@wordpress/components';
|
|
13
|
-
import { withSelect, withDispatch } from '@wordpress/data';
|
|
14
|
-
import { compose, ifCondition } from '@wordpress/compose';
|
|
15
|
-
import { store as editorStore } from '@wordpress/editor';
|
|
16
|
-
import { safeDecodeURIComponent, cleanForSlug } from '@wordpress/url';
|
|
17
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
18
|
-
import { useState } from '@wordpress/element';
|
|
19
|
-
/**
|
|
20
|
-
* Internal dependencies
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import { store as editPostStore } from '../../../store';
|
|
24
|
-
/**
|
|
25
|
-
* Module Constants
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
const PANEL_NAME = 'post-link';
|
|
29
|
-
|
|
30
|
-
function PostLink(_ref) {
|
|
31
|
-
let {
|
|
32
|
-
isOpened,
|
|
33
|
-
onTogglePanel,
|
|
34
|
-
isEditable,
|
|
35
|
-
postLink,
|
|
36
|
-
permalinkPrefix,
|
|
37
|
-
permalinkSuffix,
|
|
38
|
-
editPermalink,
|
|
39
|
-
postSlug,
|
|
40
|
-
postTypeLabel
|
|
41
|
-
} = _ref;
|
|
42
|
-
const [forceEmptyField, setForceEmptyField] = useState(false);
|
|
43
|
-
let prefixElement, postNameElement, suffixElement;
|
|
44
|
-
|
|
45
|
-
if (isEditable) {
|
|
46
|
-
prefixElement = permalinkPrefix && createElement("span", {
|
|
47
|
-
className: "edit-post-post-link__link-prefix"
|
|
48
|
-
}, permalinkPrefix);
|
|
49
|
-
postNameElement = postSlug && createElement("span", {
|
|
50
|
-
className: "edit-post-post-link__link-post-name"
|
|
51
|
-
}, postSlug);
|
|
52
|
-
suffixElement = permalinkSuffix && createElement("span", {
|
|
53
|
-
className: "edit-post-post-link__link-suffix"
|
|
54
|
-
}, permalinkSuffix);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return createElement(PanelBody, {
|
|
58
|
-
title: __('Permalink'),
|
|
59
|
-
opened: isOpened,
|
|
60
|
-
onToggle: onTogglePanel
|
|
61
|
-
}, isEditable && createElement("div", {
|
|
62
|
-
className: "editor-post-link"
|
|
63
|
-
}, createElement(TextControl, {
|
|
64
|
-
label: __('URL Slug'),
|
|
65
|
-
value: forceEmptyField ? '' : postSlug,
|
|
66
|
-
autoComplete: "off",
|
|
67
|
-
spellCheck: "false",
|
|
68
|
-
onChange: newValue => {
|
|
69
|
-
editPermalink(newValue); // When we delete the field the permalink gets
|
|
70
|
-
// reverted to the original value.
|
|
71
|
-
// The forceEmptyField logic allows the user to have
|
|
72
|
-
// the field temporarily empty while typing.
|
|
73
|
-
|
|
74
|
-
if (!newValue) {
|
|
75
|
-
if (!forceEmptyField) {
|
|
76
|
-
setForceEmptyField(true);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (forceEmptyField) {
|
|
83
|
-
setForceEmptyField(false);
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
onBlur: event => {
|
|
87
|
-
editPermalink(cleanForSlug(event.target.value));
|
|
88
|
-
|
|
89
|
-
if (forceEmptyField) {
|
|
90
|
-
setForceEmptyField(false);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}), createElement("p", null, __('The last part of the URL.'), ' ', createElement(ExternalLink, {
|
|
94
|
-
href: __('https://wordpress.org/support/article/settings-sidebar/#permalink')
|
|
95
|
-
}, __('Read about permalinks')))), createElement("h3", {
|
|
96
|
-
className: "edit-post-post-link__preview-label"
|
|
97
|
-
}, postTypeLabel || __('View post')), createElement("div", {
|
|
98
|
-
className: "edit-post-post-link__preview-link-container"
|
|
99
|
-
}, createElement(ExternalLink, {
|
|
100
|
-
className: "edit-post-post-link__link",
|
|
101
|
-
href: postLink,
|
|
102
|
-
target: "_blank"
|
|
103
|
-
}, isEditable ? createElement(Fragment, null, prefixElement, postNameElement, suffixElement) : postLink)));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export default compose([withSelect(select => {
|
|
107
|
-
const {
|
|
108
|
-
isPermalinkEditable,
|
|
109
|
-
getCurrentPost,
|
|
110
|
-
isCurrentPostPublished,
|
|
111
|
-
getPermalinkParts,
|
|
112
|
-
getEditedPostAttribute,
|
|
113
|
-
getEditedPostSlug
|
|
114
|
-
} = select(editorStore);
|
|
115
|
-
const {
|
|
116
|
-
isEditorPanelEnabled,
|
|
117
|
-
isEditorPanelOpened
|
|
118
|
-
} = select(editPostStore);
|
|
119
|
-
const {
|
|
120
|
-
getPostType
|
|
121
|
-
} = select(coreStore);
|
|
122
|
-
const {
|
|
123
|
-
link
|
|
124
|
-
} = getCurrentPost();
|
|
125
|
-
const postTypeName = getEditedPostAttribute('type');
|
|
126
|
-
const postType = getPostType(postTypeName);
|
|
127
|
-
const permalinkParts = getPermalinkParts();
|
|
128
|
-
return {
|
|
129
|
-
postLink: link,
|
|
130
|
-
isEditable: isPermalinkEditable(),
|
|
131
|
-
isPublished: isCurrentPostPublished(),
|
|
132
|
-
isOpened: isEditorPanelOpened(PANEL_NAME),
|
|
133
|
-
isEnabled: isEditorPanelEnabled(PANEL_NAME),
|
|
134
|
-
isViewable: get(postType, ['viewable'], false),
|
|
135
|
-
postSlug: safeDecodeURIComponent(getEditedPostSlug()),
|
|
136
|
-
postTypeLabel: get(postType, ['labels', 'view_item']),
|
|
137
|
-
hasPermalinkParts: !!permalinkParts,
|
|
138
|
-
permalinkPrefix: permalinkParts === null || permalinkParts === void 0 ? void 0 : permalinkParts.prefix,
|
|
139
|
-
permalinkSuffix: permalinkParts === null || permalinkParts === void 0 ? void 0 : permalinkParts.suffix
|
|
140
|
-
};
|
|
141
|
-
}), ifCondition(_ref2 => {
|
|
142
|
-
let {
|
|
143
|
-
isEnabled,
|
|
144
|
-
postLink,
|
|
145
|
-
isViewable,
|
|
146
|
-
hasPermalinkParts
|
|
147
|
-
} = _ref2;
|
|
148
|
-
return isEnabled && postLink && isViewable && hasPermalinkParts;
|
|
149
|
-
}), withDispatch(dispatch => {
|
|
150
|
-
const {
|
|
151
|
-
toggleEditorPanelOpened
|
|
152
|
-
} = dispatch(editPostStore);
|
|
153
|
-
const {
|
|
154
|
-
editPost
|
|
155
|
-
} = dispatch(editorStore);
|
|
156
|
-
return {
|
|
157
|
-
onTogglePanel: () => toggleEditorPanelOpened(PANEL_NAME),
|
|
158
|
-
editPermalink: newSlug => {
|
|
159
|
-
editPost({
|
|
160
|
-
slug: newSlug
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
})])(PostLink);
|
|
165
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/post-link/index.js"],"names":["get","__","PanelBody","TextControl","ExternalLink","withSelect","withDispatch","compose","ifCondition","store","editorStore","safeDecodeURIComponent","cleanForSlug","coreStore","useState","editPostStore","PANEL_NAME","PostLink","isOpened","onTogglePanel","isEditable","postLink","permalinkPrefix","permalinkSuffix","editPermalink","postSlug","postTypeLabel","forceEmptyField","setForceEmptyField","prefixElement","postNameElement","suffixElement","newValue","event","target","value","select","isPermalinkEditable","getCurrentPost","isCurrentPostPublished","getPermalinkParts","getEditedPostAttribute","getEditedPostSlug","isEditorPanelEnabled","isEditorPanelOpened","getPostType","link","postTypeName","postType","permalinkParts","isPublished","isEnabled","isViewable","hasPermalinkParts","prefix","suffix","dispatch","toggleEditorPanelOpened","editPost","newSlug","slug"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,SAAT,EAAoBC,WAApB,EAAiCC,YAAjC,QAAqD,uBAArD;AACA,SAASC,UAAT,EAAqBC,YAArB,QAAyC,iBAAzC;AACA,SAASC,OAAT,EAAkBC,WAAlB,QAAqC,oBAArC;AACA,SAASC,KAAK,IAAIC,WAAlB,QAAqC,mBAArC;AACA,SAASC,s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A,QAAb;AAAuB+B,IAAAA,UAAvB;AAAmCC,IAAAA;AAAnC,GAA4D;AAC1E,SAAOF,SAAS,IAAI9B,QAAb,IAAyB+B,UAAzB,IAAuCC,iBAA9C;AACA,CAFU,CAlCY,EAqCvB/C,YAAY,CAAIkD,QAAF,IAAgB;AAC7B,QAAM;AAAEC,IAAAA;AAAF,MAA8BD,QAAQ,CAAEzC,aAAF,CAA5C;AACA,QAAM;AAAE2C,IAAAA;AAAF,MAAeF,QAAQ,CAAE9C,WAAF,CAA7B;AACA,SAAO;AACNS,IAAAA,aAAa,EAAE,MAAMsC,uBAAuB,CAAEzC,UAAF,CADtC;AAENQ,IAAAA,aAAa,EAAImC,OAAF,IAAe;AAC7BD,MAAAA,QAAQ,CAAE;AAAEE,QAAAA,IAAI,EAAED;AAAR,OAAF,CAAR;AACA;AAJK,GAAP;AAMA,CATW,CArCW,CAAF,CAAP,CA+CV1C,QA/CU,CAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { PanelBody, TextControl, ExternalLink } from '@wordpress/components';\nimport { withSelect, withDispatch } from '@wordpress/data';\nimport { compose, ifCondition } from '@wordpress/compose';\nimport { store as editorStore } from '@wordpress/editor';\nimport { safeDecodeURIComponent, cleanForSlug } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as editPostStore } from '../../../store';\n\n/**\n * Module Constants\n */\nconst PANEL_NAME = 'post-link';\n\nfunction PostLink( {\n\tisOpened,\n\tonTogglePanel,\n\tisEditable,\n\tpostLink,\n\tpermalinkPrefix,\n\tpermalinkSuffix,\n\teditPermalink,\n\tpostSlug,\n\tpostTypeLabel,\n} ) {\n\tconst [ forceEmptyField, setForceEmptyField ] = useState( false );\n\n\tlet prefixElement, postNameElement, suffixElement;\n\tif ( isEditable ) {\n\t\tprefixElement = permalinkPrefix && (\n\t\t\t<span className=\"edit-post-post-link__link-prefix\">\n\t\t\t\t{ permalinkPrefix }\n\t\t\t</span>\n\t\t);\n\t\tpostNameElement = postSlug && (\n\t\t\t<span className=\"edit-post-post-link__link-post-name\">\n\t\t\t\t{ postSlug }\n\t\t\t</span>\n\t\t);\n\t\tsuffixElement = permalinkSuffix && (\n\t\t\t<span className=\"edit-post-post-link__link-suffix\">\n\t\t\t\t{ permalinkSuffix }\n\t\t\t</span>\n\t\t);\n\t}\n\n\treturn (\n\t\t<PanelBody\n\t\t\ttitle={ __( 'Permalink' ) }\n\t\t\topened={ isOpened }\n\t\t\tonToggle={ onTogglePanel }\n\t\t>\n\t\t\t{ isEditable && (\n\t\t\t\t<div className=\"editor-post-link\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\tlabel={ __( 'URL Slug' ) }\n\t\t\t\t\t\tvalue={ forceEmptyField ? '' : postSlug }\n\t\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\t\tspellCheck=\"false\"\n\t\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\t\teditPermalink( newValue );\n\t\t\t\t\t\t\t// When we delete the field the permalink gets\n\t\t\t\t\t\t\t// reverted to the original value.\n\t\t\t\t\t\t\t// The forceEmptyField logic allows the user to have\n\t\t\t\t\t\t\t// the field temporarily empty while typing.\n\t\t\t\t\t\t\tif ( ! newValue ) {\n\t\t\t\t\t\t\t\tif ( ! forceEmptyField ) {\n\t\t\t\t\t\t\t\t\tsetForceEmptyField( true );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif ( forceEmptyField ) {\n\t\t\t\t\t\t\t\tsetForceEmptyField( false );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tonBlur={ ( event ) => {\n\t\t\t\t\t\t\teditPermalink( cleanForSlug( event.target.value ) );\n\t\t\t\t\t\t\tif ( forceEmptyField ) {\n\t\t\t\t\t\t\t\tsetForceEmptyField( false );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ __( 'The last part of the URL.' ) }{ ' ' }\n\t\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\t\thref={ __(\n\t\t\t\t\t\t\t\t'https://wordpress.org/support/article/settings-sidebar/#permalink'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Read about permalinks' ) }\n\t\t\t\t\t\t</ExternalLink>\n\t\t\t\t\t</p>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<h3 className=\"edit-post-post-link__preview-label\">\n\t\t\t\t{ postTypeLabel || __( 'View post' ) }\n\t\t\t</h3>\n\t\t\t<div className=\"edit-post-post-link__preview-link-container\">\n\t\t\t\t<ExternalLink\n\t\t\t\t\tclassName=\"edit-post-post-link__link\"\n\t\t\t\t\thref={ postLink }\n\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t>\n\t\t\t\t\t{ isEditable ? (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t{ prefixElement }\n\t\t\t\t\t\t\t{ postNameElement }\n\t\t\t\t\t\t\t{ suffixElement }\n\t\t\t\t\t\t</>\n\t\t\t\t\t) : (\n\t\t\t\t\t\tpostLink\n\t\t\t\t\t) }\n\t\t\t\t</ExternalLink>\n\t\t\t</div>\n\t\t</PanelBody>\n\t);\n}\n\nexport default compose( [\n\twithSelect( ( select ) => {\n\t\tconst {\n\t\t\tisPermalinkEditable,\n\t\t\tgetCurrentPost,\n\t\t\tisCurrentPostPublished,\n\t\t\tgetPermalinkParts,\n\t\t\tgetEditedPostAttribute,\n\t\t\tgetEditedPostSlug,\n\t\t} = select( editorStore );\n\t\tconst { isEditorPanelEnabled, isEditorPanelOpened } =\n\t\t\tselect( editPostStore );\n\t\tconst { getPostType } = select( coreStore );\n\n\t\tconst { link } = getCurrentPost();\n\n\t\tconst postTypeName = getEditedPostAttribute( 'type' );\n\t\tconst postType = getPostType( postTypeName );\n\t\tconst permalinkParts = getPermalinkParts();\n\n\t\treturn {\n\t\t\tpostLink: link,\n\t\t\tisEditable: isPermalinkEditable(),\n\t\t\tisPublished: isCurrentPostPublished(),\n\t\t\tisOpened: isEditorPanelOpened( PANEL_NAME ),\n\t\t\tisEnabled: isEditorPanelEnabled( PANEL_NAME ),\n\t\t\tisViewable: get( postType, [ 'viewable' ], false ),\n\t\t\tpostSlug: safeDecodeURIComponent( getEditedPostSlug() ),\n\t\t\tpostTypeLabel: get( postType, [ 'labels', 'view_item' ] ),\n\t\t\thasPermalinkParts: !! permalinkParts,\n\t\t\tpermalinkPrefix: permalinkParts?.prefix,\n\t\t\tpermalinkSuffix: permalinkParts?.suffix,\n\t\t};\n\t} ),\n\tifCondition( ( { isEnabled, postLink, isViewable, hasPermalinkParts } ) => {\n\t\treturn isEnabled && postLink && isViewable && hasPermalinkParts;\n\t} ),\n\twithDispatch( ( dispatch ) => {\n\t\tconst { toggleEditorPanelOpened } = dispatch( editPostStore );\n\t\tconst { editPost } = dispatch( editorStore );\n\t\treturn {\n\t\t\tonTogglePanel: () => toggleEditorPanelOpened( PANEL_NAME ),\n\t\t\teditPermalink: ( newSlug ) => {\n\t\t\t\teditPost( { slug: newSlug } );\n\t\t\t},\n\t\t};\n\t} ),\n] )( PostLink );\n"]}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { createElement, Fragment } from "@wordpress/element";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* External dependencies
|
|
5
|
-
*/
|
|
6
|
-
import { kebabCase } from 'lodash';
|
|
7
|
-
/**
|
|
8
|
-
* WordPress dependencies
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { __, _x, sprintf } from '@wordpress/i18n';
|
|
12
|
-
import { Button, Modal, TextControl, Flex, FlexItem } from '@wordpress/components';
|
|
13
|
-
import { useSelect, useDispatch } from '@wordpress/data';
|
|
14
|
-
import { useState } from '@wordpress/element';
|
|
15
|
-
import { store as editorStore } from '@wordpress/editor';
|
|
16
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
17
|
-
/**
|
|
18
|
-
* Internal dependencies
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import { store as editPostStore } from '../../../store';
|
|
22
|
-
import { createBlock, serialize } from '@wordpress/blocks';
|
|
23
|
-
|
|
24
|
-
function PostTemplateActions(_ref) {
|
|
25
|
-
var _template$title$toLow;
|
|
26
|
-
|
|
27
|
-
let {
|
|
28
|
-
isPostsPage
|
|
29
|
-
} = _ref;
|
|
30
|
-
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
31
|
-
const [isBusy, setIsBusy] = useState(false);
|
|
32
|
-
const [title, setTitle] = useState('');
|
|
33
|
-
const {
|
|
34
|
-
template,
|
|
35
|
-
supportsTemplateMode,
|
|
36
|
-
defaultTemplate
|
|
37
|
-
} = useSelect(select => {
|
|
38
|
-
var _getPostType$viewable, _getPostType;
|
|
39
|
-
|
|
40
|
-
const {
|
|
41
|
-
getCurrentPostType,
|
|
42
|
-
getEditorSettings
|
|
43
|
-
} = select(editorStore);
|
|
44
|
-
const {
|
|
45
|
-
getPostType
|
|
46
|
-
} = select(coreStore);
|
|
47
|
-
const {
|
|
48
|
-
getEditedPostTemplate
|
|
49
|
-
} = select(editPostStore);
|
|
50
|
-
const isViewable = (_getPostType$viewable = (_getPostType = getPostType(getCurrentPostType())) === null || _getPostType === void 0 ? void 0 : _getPostType.viewable) !== null && _getPostType$viewable !== void 0 ? _getPostType$viewable : false;
|
|
51
|
-
|
|
52
|
-
const _supportsTemplateMode = getEditorSettings().supportsTemplateMode && isViewable;
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
template: _supportsTemplateMode && getEditedPostTemplate(),
|
|
56
|
-
supportsTemplateMode: _supportsTemplateMode,
|
|
57
|
-
defaultTemplate: getEditorSettings().defaultBlockTemplate
|
|
58
|
-
};
|
|
59
|
-
}, []);
|
|
60
|
-
const {
|
|
61
|
-
__unstableCreateTemplate,
|
|
62
|
-
__unstableSwitchToTemplateMode
|
|
63
|
-
} = useDispatch(editPostStore);
|
|
64
|
-
|
|
65
|
-
if (!supportsTemplateMode) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const defaultTitle = __('Custom Template');
|
|
70
|
-
|
|
71
|
-
async function onCreateTemplate(event) {
|
|
72
|
-
event.preventDefault();
|
|
73
|
-
|
|
74
|
-
if (isBusy) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
setIsBusy(true);
|
|
79
|
-
const newTemplateContent = defaultTemplate !== null && defaultTemplate !== void 0 ? defaultTemplate : serialize([createBlock('core/group', {
|
|
80
|
-
tagName: 'header',
|
|
81
|
-
layout: {
|
|
82
|
-
inherit: true
|
|
83
|
-
}
|
|
84
|
-
}, [createBlock('core/site-title'), createBlock('core/site-tagline')]), createBlock('core/separator'), createBlock('core/group', {
|
|
85
|
-
tagName: 'main'
|
|
86
|
-
}, [createBlock('core/group', {
|
|
87
|
-
layout: {
|
|
88
|
-
inherit: true
|
|
89
|
-
}
|
|
90
|
-
}, [createBlock('core/post-title')]), createBlock('core/post-content', {
|
|
91
|
-
layout: {
|
|
92
|
-
inherit: true
|
|
93
|
-
}
|
|
94
|
-
})])]);
|
|
95
|
-
await __unstableCreateTemplate({
|
|
96
|
-
slug: 'wp-custom-template-' + kebabCase(title || defaultTitle),
|
|
97
|
-
content: newTemplateContent,
|
|
98
|
-
title: title || defaultTitle
|
|
99
|
-
});
|
|
100
|
-
setIsBusy(false);
|
|
101
|
-
setIsModalOpen(false);
|
|
102
|
-
|
|
103
|
-
__unstableSwitchToTemplateMode(true);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return createElement(Fragment, null, createElement("div", {
|
|
107
|
-
className: "edit-post-template__actions"
|
|
108
|
-
}, !!template && createElement(Button, {
|
|
109
|
-
variant: "link",
|
|
110
|
-
onClick: () => __unstableSwitchToTemplateMode(),
|
|
111
|
-
label: sprintf( // Translators: 1: The title or the slug of the currently selected template.
|
|
112
|
-
__('Edit template: %s'), (_template$title$toLow = template === null || template === void 0 ? void 0 : template.title.toLowerCase()) !== null && _template$title$toLow !== void 0 ? _template$title$toLow : template.slug)
|
|
113
|
-
}, __('Edit')), !isPostsPage && createElement(Button, {
|
|
114
|
-
variant: "link",
|
|
115
|
-
onClick: () => setIsModalOpen(true),
|
|
116
|
-
label: _x('New template', 'action')
|
|
117
|
-
},
|
|
118
|
-
/* translators: button to create a new template */
|
|
119
|
-
_x('New', 'action'))), isModalOpen && createElement(Modal, {
|
|
120
|
-
title: __('Create custom template'),
|
|
121
|
-
closeLabel: __('Close'),
|
|
122
|
-
onRequestClose: () => {
|
|
123
|
-
setIsModalOpen(false);
|
|
124
|
-
setTitle('');
|
|
125
|
-
},
|
|
126
|
-
overlayClassName: "edit-post-template__modal"
|
|
127
|
-
}, createElement("form", {
|
|
128
|
-
onSubmit: onCreateTemplate
|
|
129
|
-
}, createElement(Flex, {
|
|
130
|
-
align: "flex-start",
|
|
131
|
-
gap: 8
|
|
132
|
-
}, createElement(FlexItem, null, createElement(TextControl, {
|
|
133
|
-
label: __('Name'),
|
|
134
|
-
value: title,
|
|
135
|
-
onChange: setTitle,
|
|
136
|
-
placeholder: defaultTitle,
|
|
137
|
-
disabled: isBusy,
|
|
138
|
-
help: __('Describe the purpose of the template, e.g. "Full Width". Custom templates can be applied to any post or page.')
|
|
139
|
-
}))), createElement(Flex, {
|
|
140
|
-
className: "edit-post-template__modal-actions",
|
|
141
|
-
justify: "flex-end",
|
|
142
|
-
expanded: false
|
|
143
|
-
}, createElement(FlexItem, null, createElement(Button, {
|
|
144
|
-
variant: "tertiary",
|
|
145
|
-
onClick: () => {
|
|
146
|
-
setIsModalOpen(false);
|
|
147
|
-
setTitle('');
|
|
148
|
-
}
|
|
149
|
-
}, __('Cancel'))), createElement(FlexItem, null, createElement(Button, {
|
|
150
|
-
variant: "primary",
|
|
151
|
-
type: "submit",
|
|
152
|
-
isBusy: isBusy,
|
|
153
|
-
"aria-disabled": isBusy
|
|
154
|
-
}, __('Create')))))));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export default PostTemplateActions;
|
|
158
|
-
//# sourceMappingURL=actions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-post/src/components/sidebar/template/actions.js"],"names":["kebabCase","__","_x","sprintf","Button","Modal","TextControl","Flex","FlexItem","useSelect","useDispatch","useState","store","editorStore","coreStore","editPostStore","createBlock","serialize","PostTemplateActions","isPostsPage","isModalOpen","setIsModalOpen","isBusy","setIsBusy","title","setTitle","template","supportsTemplateMode","defaultTemplate","select","getCurrentPostType","getEditorSettings","getPostType","getEditedPostTemplate","isViewable","viewable","_supportsTemplateMode","defaultBlockTemplate","__unstableCreateTemplate","__unstableSwitchToTemplateMode","defaultTitle","onCreateTemplate","event","preventDefault","newTemplateContent","tagName","layout","inherit","slug","content","toLowerCase"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,QAA1B;AAEA;AACA;AACA;;AACA,SAASC,EAAT,EAAaC,EAAb,EAAiBC,OAAjB,QAAgC,iBAAhC;AACA,SACCC,MADD,EAECC,KAFD,EAGCC,WAHD,EAICC,IAJD,EAKCC,QALD,QAMO,uBANP;AAOA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,KAAK,IAAIC,WAAlB,QAAqC,mBAArC;AACA,SAASD,KAAK,IAAIE,SAAlB,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,SAASF,KAAK,IAAIG,aAAlB,QAAuC,gBAAvC;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,mBAAvC;;AAEA,SAASC,mBAAT,OAAgD;AAAA;;AAAA,MAAlB;AAAEC,IAAA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AAEC,IAAA,OAAO,EAAC,UAFT;AAGC,IAAA,QAAQ,EAAG;AAHZ,KAKC,cAAC,QAAD,QACC,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,UADT;AAEC,IAAA,OAAO,EAAG,MAAM;AACfoB,MAAAA,cAAc,CAAE,KAAF,CAAd;AACAI,MAAAA,QAAQ,CAAE,EAAF,CAAR;AACA;AALF,KAOGxB,EAAE,CAAE,QAAF,CAPL,CADD,CALD,EAgBC,cAAC,QAAD,QACC,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,IAAI,EAAC,QAFN;AAGC,IAAA,MAAM,EAAGqB,MAHV;AAIC,qBAAgBA;AAJjB,KAMGrB,EAAE,CAAE,QAAF,CANL,CADD,CAhBD,CAhBD,CATD,CA7BF,CADD;AAuFA;;AAED,eAAeiB,mBAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { kebabCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport {\n\tButton,\n\tModal,\n\tTextControl,\n\tFlex,\n\tFlexItem,\n} from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\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 { createBlock, serialize } from '@wordpress/blocks';\n\nfunction PostTemplateActions( { isPostsPage } ) {\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst [ isBusy, setIsBusy ] = useState( false );\n\tconst [ title, setTitle ] = useState( '' );\n\tconst { template, supportsTemplateMode, defaultTemplate } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCurrentPostType, getEditorSettings } =\n\t\t\t\tselect( editorStore );\n\t\t\tconst { getPostType } = select( coreStore );\n\t\t\tconst { getEditedPostTemplate } = select( editPostStore );\n\n\t\t\tconst isViewable =\n\t\t\t\tgetPostType( getCurrentPostType() )?.viewable ?? false;\n\t\t\tconst _supportsTemplateMode =\n\t\t\t\tgetEditorSettings().supportsTemplateMode && isViewable;\n\n\t\t\treturn {\n\t\t\t\ttemplate: _supportsTemplateMode && getEditedPostTemplate(),\n\t\t\t\tsupportsTemplateMode: _supportsTemplateMode,\n\t\t\t\tdefaultTemplate: getEditorSettings().defaultBlockTemplate,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\tconst { __unstableCreateTemplate, __unstableSwitchToTemplateMode } =\n\t\tuseDispatch( editPostStore );\n\n\tif ( ! supportsTemplateMode ) {\n\t\treturn null;\n\t}\n\n\tconst defaultTitle = __( 'Custom Template' );\n\n\tasync function onCreateTemplate( event ) {\n\t\tevent.preventDefault();\n\n\t\tif ( isBusy ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsBusy( true );\n\n\t\tconst newTemplateContent =\n\t\t\tdefaultTemplate ??\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: 'wp-custom-template-' + kebabCase( title || defaultTitle ),\n\t\t\tcontent: newTemplateContent,\n\t\t\ttitle: title || defaultTitle,\n\t\t} );\n\n\t\tsetIsBusy( false );\n\t\tsetIsModalOpen( false );\n\n\t\t__unstableSwitchToTemplateMode( true );\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<div className=\"edit-post-template__actions\">\n\t\t\t\t{ !! template && (\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\tlabel={ sprintf(\n\t\t\t\t\t\t\t// Translators: 1: The title or the slug of the currently selected template.\n\t\t\t\t\t\t\t__( 'Edit template: %s' ),\n\t\t\t\t\t\t\ttemplate?.title.toLowerCase() ?? template.slug\n\t\t\t\t\t\t) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Edit' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\t\t\t\t{ ! isPostsPage && (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"link\"\n\t\t\t\t\t\tonClick={ () => setIsModalOpen( true ) }\n\t\t\t\t\t\tlabel={ _x( 'New template', 'action' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/* translators: button to create a new template */\n\t\t\t\t\t\t\t_x( 'New', 'action' )\n\t\t\t\t\t\t}\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Create custom template' ) }\n\t\t\t\t\tcloseLabel={ __( 'Close' ) }\n\t\t\t\t\tonRequestClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t} }\n\t\t\t\t\toverlayClassName=\"edit-post-template__modal\"\n\t\t\t\t>\n\t\t\t\t\t<form onSubmit={ onCreateTemplate }>\n\t\t\t\t\t\t<Flex align=\"flex-start\" gap={ 8 }>\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\t\t\t\tplaceholder={ defaultTitle }\n\t\t\t\t\t\t\t\t\tdisabled={ isBusy }\n\t\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t\t'Describe the purpose of the template, e.g. \"Full Width\". Custom templates can be applied to any post or page.'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t</Flex>\n\n\t\t\t\t\t\t<Flex\n\t\t\t\t\t\t\tclassName=\"edit-post-template__modal-actions\"\n\t\t\t\t\t\t\tjustify=\"flex-end\"\n\t\t\t\t\t\t\texpanded={ false }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\t\t\t\t\tsetTitle( '' );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\t\t\tisBusy={ isBusy }\n\t\t\t\t\t\t\t\t\taria-disabled={ isBusy }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t</Flex>\n\t\t\t\t\t</form>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default PostTemplateActions;\n"]}
|