@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
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
5
|
+
import { store as editorStore } from '@wordpress/editor';
|
|
6
|
+
import { useState } from '@wordpress/element';
|
|
7
|
+
import { serialize, createBlock } from '@wordpress/blocks';
|
|
8
|
+
import {
|
|
9
|
+
Modal,
|
|
10
|
+
Flex,
|
|
11
|
+
FlexItem,
|
|
12
|
+
TextControl,
|
|
13
|
+
Button,
|
|
14
|
+
} from '@wordpress/components';
|
|
15
|
+
import { __ } from '@wordpress/i18n';
|
|
16
|
+
import { cleanForSlug } from '@wordpress/url';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Internal dependencies
|
|
20
|
+
*/
|
|
21
|
+
import { store as editPostStore } from '../../../store';
|
|
22
|
+
|
|
23
|
+
const DEFAULT_TITLE = __( 'Custom Template' );
|
|
24
|
+
|
|
25
|
+
export default function PostTemplateCreateModal( { onClose } ) {
|
|
26
|
+
const defaultBlockTemplate = useSelect(
|
|
27
|
+
( select ) =>
|
|
28
|
+
select( editorStore ).getEditorSettings().defaultBlockTemplate,
|
|
29
|
+
[]
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const { __unstableCreateTemplate, __unstableSwitchToTemplateMode } =
|
|
33
|
+
useDispatch( editPostStore );
|
|
34
|
+
|
|
35
|
+
const [ title, setTitle ] = useState( '' );
|
|
36
|
+
|
|
37
|
+
const [ isBusy, setIsBusy ] = useState( false );
|
|
38
|
+
|
|
39
|
+
const cancel = () => {
|
|
40
|
+
setTitle( '' );
|
|
41
|
+
onClose();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const submit = async ( event ) => {
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
|
|
47
|
+
if ( isBusy ) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
setIsBusy( true );
|
|
52
|
+
|
|
53
|
+
const newTemplateContent =
|
|
54
|
+
defaultBlockTemplate ??
|
|
55
|
+
serialize( [
|
|
56
|
+
createBlock(
|
|
57
|
+
'core/group',
|
|
58
|
+
{
|
|
59
|
+
tagName: 'header',
|
|
60
|
+
layout: { inherit: true },
|
|
61
|
+
},
|
|
62
|
+
[
|
|
63
|
+
createBlock( 'core/site-title' ),
|
|
64
|
+
createBlock( 'core/site-tagline' ),
|
|
65
|
+
]
|
|
66
|
+
),
|
|
67
|
+
createBlock( 'core/separator' ),
|
|
68
|
+
createBlock(
|
|
69
|
+
'core/group',
|
|
70
|
+
{
|
|
71
|
+
tagName: 'main',
|
|
72
|
+
},
|
|
73
|
+
[
|
|
74
|
+
createBlock(
|
|
75
|
+
'core/group',
|
|
76
|
+
{
|
|
77
|
+
layout: { inherit: true },
|
|
78
|
+
},
|
|
79
|
+
[ createBlock( 'core/post-title' ) ]
|
|
80
|
+
),
|
|
81
|
+
createBlock( 'core/post-content', {
|
|
82
|
+
layout: { inherit: true },
|
|
83
|
+
} ),
|
|
84
|
+
]
|
|
85
|
+
),
|
|
86
|
+
] );
|
|
87
|
+
|
|
88
|
+
await __unstableCreateTemplate( {
|
|
89
|
+
slug: cleanForSlug( title || DEFAULT_TITLE ),
|
|
90
|
+
content: newTemplateContent,
|
|
91
|
+
title: title || DEFAULT_TITLE,
|
|
92
|
+
} );
|
|
93
|
+
|
|
94
|
+
setIsBusy( false );
|
|
95
|
+
cancel();
|
|
96
|
+
|
|
97
|
+
__unstableSwitchToTemplateMode( true );
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<Modal
|
|
102
|
+
title={ __( 'Create custom template' ) }
|
|
103
|
+
closeLabel={ __( 'Close' ) }
|
|
104
|
+
onRequestClose={ cancel }
|
|
105
|
+
className="edit-post-post-template__create-modal"
|
|
106
|
+
>
|
|
107
|
+
<form
|
|
108
|
+
className="edit-post-post-template__create-form"
|
|
109
|
+
onSubmit={ submit }
|
|
110
|
+
>
|
|
111
|
+
<Flex align="flex-start" gap={ 8 }>
|
|
112
|
+
<FlexItem>
|
|
113
|
+
<TextControl
|
|
114
|
+
label={ __( 'Name' ) }
|
|
115
|
+
value={ title }
|
|
116
|
+
onChange={ setTitle }
|
|
117
|
+
placeholder={ DEFAULT_TITLE }
|
|
118
|
+
disabled={ isBusy }
|
|
119
|
+
help={ __(
|
|
120
|
+
'Describe the template, e.g. "Post with sidebar". Custom templates can be applied to any post or page.'
|
|
121
|
+
) }
|
|
122
|
+
/>
|
|
123
|
+
</FlexItem>
|
|
124
|
+
</Flex>
|
|
125
|
+
|
|
126
|
+
<Flex justify="flex-end" expanded={ false }>
|
|
127
|
+
<FlexItem>
|
|
128
|
+
<Button variant="tertiary" onClick={ cancel }>
|
|
129
|
+
{ __( 'Cancel' ) }
|
|
130
|
+
</Button>
|
|
131
|
+
</FlexItem>
|
|
132
|
+
<FlexItem>
|
|
133
|
+
<Button
|
|
134
|
+
variant="primary"
|
|
135
|
+
type="submit"
|
|
136
|
+
isBusy={ isBusy }
|
|
137
|
+
aria-disabled={ isBusy }
|
|
138
|
+
>
|
|
139
|
+
{ __( 'Create' ) }
|
|
140
|
+
</Button>
|
|
141
|
+
</FlexItem>
|
|
142
|
+
</Flex>
|
|
143
|
+
</form>
|
|
144
|
+
</Modal>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useState, useMemo } from '@wordpress/element';
|
|
5
|
+
import { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '@wordpress/block-editor';
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
import { addTemplate } from '@wordpress/icons';
|
|
8
|
+
import { Notice, SelectControl, Button } from '@wordpress/components';
|
|
9
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
10
|
+
import { store as editorStore } from '@wordpress/editor';
|
|
11
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import { store as editPostStore } from '../../../store';
|
|
17
|
+
import PostTemplateCreateModal from './create-modal';
|
|
18
|
+
|
|
19
|
+
export default function PostTemplateForm( { onClose } ) {
|
|
20
|
+
const {
|
|
21
|
+
isPostsPage,
|
|
22
|
+
availableTemplates,
|
|
23
|
+
fetchedTemplates,
|
|
24
|
+
selectedTemplateSlug,
|
|
25
|
+
canCreate,
|
|
26
|
+
canEdit,
|
|
27
|
+
} = useSelect( ( select ) => {
|
|
28
|
+
const editorSettings = select( editorStore ).getEditorSettings();
|
|
29
|
+
const siteSettings = select( coreStore ).getEntityRecord(
|
|
30
|
+
'root',
|
|
31
|
+
'site'
|
|
32
|
+
);
|
|
33
|
+
const _isPostsPage =
|
|
34
|
+
select( editorStore ).getCurrentPostId() ===
|
|
35
|
+
siteSettings?.page_for_posts;
|
|
36
|
+
const canCreateTemplates = select( coreStore ).canUser(
|
|
37
|
+
'create',
|
|
38
|
+
'templates'
|
|
39
|
+
);
|
|
40
|
+
return {
|
|
41
|
+
isPostsPage: _isPostsPage,
|
|
42
|
+
availableTemplates: editorSettings.availableTemplates,
|
|
43
|
+
fetchedTemplates: select( coreStore ).getEntityRecords(
|
|
44
|
+
'postType',
|
|
45
|
+
'wp_template',
|
|
46
|
+
{
|
|
47
|
+
post_type: select( editorStore ).getCurrentPostType(),
|
|
48
|
+
per_page: -1,
|
|
49
|
+
}
|
|
50
|
+
),
|
|
51
|
+
selectedTemplateSlug:
|
|
52
|
+
select( editorStore ).getEditedPostAttribute( 'template' ),
|
|
53
|
+
canCreate:
|
|
54
|
+
canCreateTemplates &&
|
|
55
|
+
! _isPostsPage &&
|
|
56
|
+
editorSettings.supportsTemplateMode,
|
|
57
|
+
canEdit:
|
|
58
|
+
canCreateTemplates &&
|
|
59
|
+
editorSettings.supportsTemplateMode &&
|
|
60
|
+
!! select( editPostStore ).getEditedPostTemplate(),
|
|
61
|
+
};
|
|
62
|
+
}, [] );
|
|
63
|
+
|
|
64
|
+
const options = useMemo(
|
|
65
|
+
() =>
|
|
66
|
+
Object.entries( {
|
|
67
|
+
...availableTemplates,
|
|
68
|
+
...Object.fromEntries(
|
|
69
|
+
( fetchedTemplates ?? [] ).map( ( { slug, title } ) => [
|
|
70
|
+
slug,
|
|
71
|
+
title.rendered,
|
|
72
|
+
] )
|
|
73
|
+
),
|
|
74
|
+
} ).map( ( [ slug, title ] ) => ( { value: slug, label: title } ) ),
|
|
75
|
+
[ availableTemplates, fetchedTemplates ]
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const selectedOption =
|
|
79
|
+
options.find( ( option ) => option.value === selectedTemplateSlug ) ??
|
|
80
|
+
options.find( ( option ) => ! option.value ); // The default option has '' value.
|
|
81
|
+
|
|
82
|
+
const { editPost } = useDispatch( editorStore );
|
|
83
|
+
const { __unstableSwitchToTemplateMode } = useDispatch( editPostStore );
|
|
84
|
+
|
|
85
|
+
const [ isCreateModalOpen, setIsCreateModalOpen ] = useState( false );
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div className="edit-post-post-template__form">
|
|
89
|
+
<InspectorPopoverHeader
|
|
90
|
+
title={ __( 'Template' ) }
|
|
91
|
+
help={ __(
|
|
92
|
+
'Templates define the way content is displayed when viewing your site.'
|
|
93
|
+
) }
|
|
94
|
+
actions={
|
|
95
|
+
canCreate
|
|
96
|
+
? [
|
|
97
|
+
{
|
|
98
|
+
icon: addTemplate,
|
|
99
|
+
label: __( 'Add template' ),
|
|
100
|
+
onClick: () => setIsCreateModalOpen( true ),
|
|
101
|
+
},
|
|
102
|
+
]
|
|
103
|
+
: []
|
|
104
|
+
}
|
|
105
|
+
onClose={ onClose }
|
|
106
|
+
/>
|
|
107
|
+
{ isPostsPage ? (
|
|
108
|
+
<Notice
|
|
109
|
+
className="edit-post-post-template__notice"
|
|
110
|
+
status="warning"
|
|
111
|
+
isDismissible={ false }
|
|
112
|
+
>
|
|
113
|
+
{ __( 'The posts page template cannot be changed.' ) }
|
|
114
|
+
</Notice>
|
|
115
|
+
) : (
|
|
116
|
+
<SelectControl
|
|
117
|
+
hideLabelFromVision
|
|
118
|
+
label={ __( 'Template' ) }
|
|
119
|
+
value={ selectedOption?.value ?? '' }
|
|
120
|
+
options={ options }
|
|
121
|
+
onChange={ ( slug ) =>
|
|
122
|
+
editPost( { template: slug || '' } )
|
|
123
|
+
}
|
|
124
|
+
/>
|
|
125
|
+
) }
|
|
126
|
+
{ canEdit && (
|
|
127
|
+
<p>
|
|
128
|
+
<Button
|
|
129
|
+
variant="link"
|
|
130
|
+
onClick={ () => __unstableSwitchToTemplateMode() }
|
|
131
|
+
>
|
|
132
|
+
{ __( 'Edit template' ) }
|
|
133
|
+
</Button>
|
|
134
|
+
</p>
|
|
135
|
+
) }
|
|
136
|
+
{ isCreateModalOpen && (
|
|
137
|
+
<PostTemplateCreateModal
|
|
138
|
+
onClose={ () => setIsCreateModalOpen( false ) }
|
|
139
|
+
/>
|
|
140
|
+
) }
|
|
141
|
+
</div>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useRef } from '@wordpress/element';
|
|
5
|
+
import { PanelRow, Dropdown, Button } from '@wordpress/components';
|
|
6
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
7
|
+
import { useSelect } from '@wordpress/data';
|
|
8
|
+
import { store as editorStore } from '@wordpress/editor';
|
|
9
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import PostTemplateForm from './form';
|
|
15
|
+
|
|
16
|
+
export default function PostTemplate() {
|
|
17
|
+
const anchorRef = useRef();
|
|
18
|
+
|
|
19
|
+
const isVisible = useSelect( ( select ) => {
|
|
20
|
+
const postTypeSlug = select( editorStore ).getCurrentPostType();
|
|
21
|
+
const postType = select( coreStore ).getPostType( postTypeSlug );
|
|
22
|
+
if ( ! postType?.viewable ) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const settings = select( editorStore ).getEditorSettings();
|
|
27
|
+
const hasTemplates =
|
|
28
|
+
!! settings.availableTemplates &&
|
|
29
|
+
Object.keys( settings.availableTemplates ).length > 0;
|
|
30
|
+
if ( hasTemplates ) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if ( ! settings.supportsTemplateMode ) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const canCreateTemplates =
|
|
39
|
+
select( coreStore ).canUser( 'create', 'templates' ) ?? false;
|
|
40
|
+
return canCreateTemplates;
|
|
41
|
+
}, [] );
|
|
42
|
+
|
|
43
|
+
if ( ! isVisible ) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<PanelRow className="edit-post-post-template" ref={ anchorRef }>
|
|
49
|
+
<span>{ __( 'Template' ) }</span>
|
|
50
|
+
<Dropdown
|
|
51
|
+
popoverProps={ { anchorRef } }
|
|
52
|
+
position="bottom left"
|
|
53
|
+
className="edit-post-post-template__dropdown"
|
|
54
|
+
contentClassName="edit-post-post-template__dialog"
|
|
55
|
+
focusOnMount
|
|
56
|
+
renderToggle={ ( { isOpen, onToggle } ) => (
|
|
57
|
+
<PostTemplateToggle
|
|
58
|
+
isOpen={ isOpen }
|
|
59
|
+
onClick={ onToggle }
|
|
60
|
+
/>
|
|
61
|
+
) }
|
|
62
|
+
renderContent={ ( { onClose } ) => (
|
|
63
|
+
<PostTemplateForm onClose={ onClose } />
|
|
64
|
+
) }
|
|
65
|
+
/>
|
|
66
|
+
</PanelRow>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function PostTemplateToggle( { isOpen, onClick } ) {
|
|
71
|
+
const templateTitle = useSelect( ( select ) => {
|
|
72
|
+
const templateSlug =
|
|
73
|
+
select( editorStore ).getEditedPostAttribute( 'template' );
|
|
74
|
+
|
|
75
|
+
const settings = select( editorStore ).getEditorSettings();
|
|
76
|
+
if ( settings.availableTemplates[ templateSlug ] ) {
|
|
77
|
+
return settings.availableTemplates[ templateSlug ];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const template = select( coreStore )
|
|
81
|
+
.getEntityRecords( 'postType', 'wp_template', { per_page: -1 } )
|
|
82
|
+
?.find( ( { slug } ) => slug === templateSlug );
|
|
83
|
+
|
|
84
|
+
return template?.title.rendered;
|
|
85
|
+
}, [] );
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<Button
|
|
89
|
+
className="edit-post-post-template__toggle"
|
|
90
|
+
variant="tertiary"
|
|
91
|
+
aria-expanded={ isOpen }
|
|
92
|
+
aria-label={
|
|
93
|
+
templateTitle
|
|
94
|
+
? sprintf(
|
|
95
|
+
// translators: %s: Name of the currently selected template.
|
|
96
|
+
__( 'Select template: %s' ),
|
|
97
|
+
templateTitle
|
|
98
|
+
)
|
|
99
|
+
: __( 'Select template' )
|
|
100
|
+
}
|
|
101
|
+
onClick={ onClick }
|
|
102
|
+
>
|
|
103
|
+
{ templateTitle ?? __( 'Default template' ) }
|
|
104
|
+
</Button>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
.edit-post-post-template {
|
|
2
|
+
width: 100%;
|
|
3
|
+
justify-content: flex-start;
|
|
4
|
+
|
|
5
|
+
span {
|
|
6
|
+
display: block;
|
|
7
|
+
width: 45%;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.edit-post-post-template__dropdown {
|
|
12
|
+
max-width: 55%;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.components-button.edit-post-post-template__toggle {
|
|
16
|
+
display: inline-block;
|
|
17
|
+
width: 100%;
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
text-overflow: ellipsis;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.edit-post-post-template__dialog {
|
|
23
|
+
z-index: z-index(".edit-post-post-template__dialog");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.edit-post-post-template__form {
|
|
27
|
+
// sidebar width - popover padding - form margin
|
|
28
|
+
min-width: $sidebar-width - $grid-unit-20 - $grid-unit-20;
|
|
29
|
+
margin: $grid-unit-10;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.edit-post-post-template__create-form {
|
|
33
|
+
@include break-medium() {
|
|
34
|
+
width: $grid-unit * 40;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useRef } from '@wordpress/element';
|
|
5
|
+
import { PanelRow, Dropdown, Button } from '@wordpress/components';
|
|
6
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
7
|
+
import {
|
|
8
|
+
PostURLCheck,
|
|
9
|
+
PostURL as PostURLForm,
|
|
10
|
+
usePostURLLabel,
|
|
11
|
+
} from '@wordpress/editor';
|
|
12
|
+
|
|
13
|
+
export default function PostURL() {
|
|
14
|
+
const anchorRef = useRef();
|
|
15
|
+
return (
|
|
16
|
+
<PostURLCheck>
|
|
17
|
+
<PanelRow className="edit-post-post-url" ref={ anchorRef }>
|
|
18
|
+
<span>{ __( 'URL' ) }</span>
|
|
19
|
+
<Dropdown
|
|
20
|
+
popoverProps={ { anchorRef } }
|
|
21
|
+
position="bottom left"
|
|
22
|
+
className="edit-post-post-url__dropdown"
|
|
23
|
+
contentClassName="edit-post-post-url__dialog"
|
|
24
|
+
focusOnMount
|
|
25
|
+
renderToggle={ ( { isOpen, onToggle } ) => (
|
|
26
|
+
<PostURLToggle isOpen={ isOpen } onClick={ onToggle } />
|
|
27
|
+
) }
|
|
28
|
+
renderContent={ ( { onClose } ) => (
|
|
29
|
+
<PostURLForm onClose={ onClose } />
|
|
30
|
+
) }
|
|
31
|
+
/>
|
|
32
|
+
</PanelRow>
|
|
33
|
+
</PostURLCheck>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function PostURLToggle( { isOpen, onClick } ) {
|
|
38
|
+
const label = usePostURLLabel();
|
|
39
|
+
return (
|
|
40
|
+
<Button
|
|
41
|
+
className="edit-post-post-url__toggle"
|
|
42
|
+
variant="tertiary"
|
|
43
|
+
aria-expanded={ isOpen }
|
|
44
|
+
// translators: %s: Current post URL.
|
|
45
|
+
aria-label={ sprintf( __( 'Change URL: %s' ), label ) }
|
|
46
|
+
onClick={ onClick }
|
|
47
|
+
>
|
|
48
|
+
{ label }
|
|
49
|
+
</Button>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
.edit-post-post-url {
|
|
2
|
+
width: 100%;
|
|
3
|
+
justify-content: flex-start;
|
|
4
|
+
|
|
5
|
+
span {
|
|
6
|
+
display: block;
|
|
7
|
+
width: 45%;
|
|
8
|
+
flex-shrink: 0;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.components-button.edit-post-post-url__toggle {
|
|
13
|
+
text-align: left;
|
|
14
|
+
white-space: normal;
|
|
15
|
+
height: auto;
|
|
16
|
+
word-break: break-word;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.edit-post-post-url__dialog .editor-post-url {
|
|
20
|
+
// sidebar width - popover padding - form margin
|
|
21
|
+
min-width: $sidebar-width - $grid-unit-20 - $grid-unit-20;
|
|
22
|
+
margin: $grid-unit-10;
|
|
23
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { __ } from '@wordpress/i18n';
|
|
4
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
5
5
|
import { PanelRow, Dropdown, Button } from '@wordpress/components';
|
|
6
6
|
import {
|
|
7
7
|
PostVisibility as PostVisibilityForm,
|
|
8
8
|
PostVisibilityLabel,
|
|
9
9
|
PostVisibilityCheck,
|
|
10
|
+
usePostVisibilityLabel,
|
|
10
11
|
} from '@wordpress/editor';
|
|
11
12
|
import { useRef } from '@wordpress/element';
|
|
12
13
|
|
|
@@ -32,15 +33,12 @@ export function PostVisibility() {
|
|
|
32
33
|
// when the label changes.
|
|
33
34
|
anchorRef: rowRef.current,
|
|
34
35
|
} }
|
|
36
|
+
focusOnMount
|
|
35
37
|
renderToggle={ ( { isOpen, onToggle } ) => (
|
|
36
|
-
<
|
|
37
|
-
|
|
38
|
-
className="edit-post-post-visibility__toggle"
|
|
38
|
+
<PostVisibilityToggle
|
|
39
|
+
isOpen={ isOpen }
|
|
39
40
|
onClick={ onToggle }
|
|
40
|
-
|
|
41
|
-
>
|
|
42
|
-
<PostVisibilityLabel />
|
|
43
|
-
</Button>
|
|
41
|
+
/>
|
|
44
42
|
) }
|
|
45
43
|
renderContent={ ( { onClose } ) => (
|
|
46
44
|
<PostVisibilityForm onClose={ onClose } />
|
|
@@ -53,4 +51,20 @@ export function PostVisibility() {
|
|
|
53
51
|
);
|
|
54
52
|
}
|
|
55
53
|
|
|
54
|
+
function PostVisibilityToggle( { isOpen, onClick } ) {
|
|
55
|
+
const label = usePostVisibilityLabel();
|
|
56
|
+
return (
|
|
57
|
+
<Button
|
|
58
|
+
className="edit-post-post-visibility__toggle"
|
|
59
|
+
variant="tertiary"
|
|
60
|
+
aria-expanded={ isOpen }
|
|
61
|
+
// translators: %s: Current post visibility.
|
|
62
|
+
aria-label={ sprintf( __( 'Select visibility: %s' ), label ) }
|
|
63
|
+
onClick={ onClick }
|
|
64
|
+
>
|
|
65
|
+
{ label }
|
|
66
|
+
</Button>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
56
70
|
export default PostVisibility;
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
.edit-post-post-visibility__dialog .
|
|
12
|
-
// sidebar width - padding -
|
|
13
|
-
width: $sidebar-width - $grid-unit-20 - $
|
|
14
|
-
|
|
11
|
+
.edit-post-post-visibility__dialog .editor-post-visibility {
|
|
12
|
+
// sidebar width - popover padding - form margin
|
|
13
|
+
min-width: $sidebar-width - $grid-unit-20 - $grid-unit-20;
|
|
14
|
+
margin: $grid-unit-10;
|
|
15
15
|
}
|
|
@@ -19,13 +19,11 @@ import LastRevision from '../last-revision';
|
|
|
19
19
|
import PostTaxonomies from '../post-taxonomies';
|
|
20
20
|
import FeaturedImage from '../featured-image';
|
|
21
21
|
import PostExcerpt from '../post-excerpt';
|
|
22
|
-
import PostLink from '../post-link';
|
|
23
22
|
import DiscussionPanel from '../discussion-panel';
|
|
24
23
|
import PageAttributes from '../page-attributes';
|
|
25
24
|
import MetaBoxes from '../../meta-boxes';
|
|
26
25
|
import PluginDocumentSettingPanel from '../plugin-document-setting-panel';
|
|
27
26
|
import PluginSidebarEditPost from '../plugin-sidebar';
|
|
28
|
-
import Template from '../template';
|
|
29
27
|
import TemplateSummary from '../template-summary';
|
|
30
28
|
import { __ } from '@wordpress/i18n';
|
|
31
29
|
import { useSelect } from '@wordpress/data';
|
|
@@ -42,7 +40,7 @@ const SettingsSidebar = () => {
|
|
|
42
40
|
// The settings sidebar is used by the edit-post/document and edit-post/block sidebars.
|
|
43
41
|
// sidebarName represents the sidebar that is active or that should be active when the SettingsSidebar toggle button is pressed.
|
|
44
42
|
// If one of the two sidebars is active the component will contain the content of that sidebar.
|
|
45
|
-
// When neither of the
|
|
43
|
+
// When neither of the two sidebars is active we can not simply return null, because the PluginSidebarEditPost
|
|
46
44
|
// component, besides being used to render the sidebar, also renders the toggle button. In that case sidebarName
|
|
47
45
|
// should contain the sidebar that will be active when the toggle button is pressed. If a block
|
|
48
46
|
// is selected, that should be edit-post/block otherwise it's edit-post/document.
|
|
@@ -86,10 +84,8 @@ const SettingsSidebar = () => {
|
|
|
86
84
|
{ ! isTemplateMode && sidebarName === 'edit-post/document' && (
|
|
87
85
|
<>
|
|
88
86
|
<PostStatus />
|
|
89
|
-
<Template />
|
|
90
87
|
<PluginDocumentSettingPanel.Slot />
|
|
91
88
|
<LastRevision />
|
|
92
|
-
<PostLink />
|
|
93
89
|
<PostTaxonomies />
|
|
94
90
|
<FeaturedImage />
|
|
95
91
|
<PostExcerpt />
|