@wordpress/edit-post 6.8.0 → 6.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +1 -1
  3. package/build/components/keyboard-shortcut-help-modal/config.js +12 -0
  4. package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
  5. package/build/components/sidebar/plugin-post-status-info/index.js +2 -2
  6. package/build/components/sidebar/plugin-post-status-info/index.js.map +1 -1
  7. package/build/components/sidebar/post-schedule/index.js +6 -6
  8. package/build/components/sidebar/post-schedule/index.js.map +1 -1
  9. package/build/components/sidebar/post-status/index.js +4 -2
  10. package/build/components/sidebar/post-status/index.js.map +1 -1
  11. package/build/components/sidebar/post-template/create-modal.js +116 -0
  12. package/build/components/sidebar/post-template/create-modal.js.map +1 -0
  13. package/build/components/sidebar/post-template/form.js +123 -0
  14. package/build/components/sidebar/post-template/form.js.map +1 -0
  15. package/build/components/sidebar/post-template/index.js +123 -0
  16. package/build/components/sidebar/post-template/index.js.map +1 -0
  17. package/build/components/sidebar/settings-sidebar/index.js +1 -3
  18. package/build/components/sidebar/settings-sidebar/index.js.map +1 -1
  19. package/build/components/start-page-options/index.js +31 -13
  20. package/build/components/start-page-options/index.js.map +1 -1
  21. package/build/editor.js +1 -1
  22. package/build/editor.js.map +1 -1
  23. package/build/editor.native.js +1 -1
  24. package/build/editor.native.js.map +1 -1
  25. package/build/store/selectors.js +8 -8
  26. package/build/store/selectors.js.map +1 -1
  27. package/build-module/components/keyboard-shortcut-help-modal/config.js +12 -0
  28. package/build-module/components/keyboard-shortcut-help-modal/config.js.map +1 -1
  29. package/build-module/components/sidebar/plugin-post-status-info/index.js +2 -2
  30. package/build-module/components/sidebar/plugin-post-status-info/index.js.map +1 -1
  31. package/build-module/components/sidebar/post-schedule/index.js +7 -4
  32. package/build-module/components/sidebar/post-schedule/index.js.map +1 -1
  33. package/build-module/components/sidebar/post-status/index.js +3 -2
  34. package/build-module/components/sidebar/post-status/index.js.map +1 -1
  35. package/build-module/components/sidebar/post-template/create-modal.js +104 -0
  36. package/build-module/components/sidebar/post-template/create-modal.js.map +1 -0
  37. package/build-module/components/sidebar/post-template/form.js +106 -0
  38. package/build-module/components/sidebar/post-template/form.js.map +1 -0
  39. package/build-module/components/sidebar/post-template/index.js +109 -0
  40. package/build-module/components/sidebar/post-template/index.js.map +1 -0
  41. package/build-module/components/sidebar/settings-sidebar/index.js +1 -2
  42. package/build-module/components/sidebar/settings-sidebar/index.js.map +1 -1
  43. package/build-module/components/start-page-options/index.js +32 -14
  44. package/build-module/components/start-page-options/index.js.map +1 -1
  45. package/build-module/editor.js +2 -2
  46. package/build-module/editor.js.map +1 -1
  47. package/build-module/editor.native.js +2 -2
  48. package/build-module/editor.native.js.map +1 -1
  49. package/build-module/store/selectors.js +8 -7
  50. package/build-module/store/selectors.js.map +1 -1
  51. package/build-style/style-rtl.css +56 -44
  52. package/build-style/style.css +56 -44
  53. package/package.json +27 -27
  54. package/src/components/keyboard-shortcut-help-modal/config.js +8 -0
  55. package/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap +14 -0
  56. package/src/components/sidebar/plugin-post-status-info/index.js +2 -2
  57. package/src/components/sidebar/post-schedule/index.js +5 -3
  58. package/src/components/sidebar/post-schedule/style.scss +18 -3
  59. package/src/components/sidebar/post-status/index.js +3 -1
  60. package/src/components/sidebar/post-template/create-modal.js +146 -0
  61. package/src/components/sidebar/post-template/form.js +140 -0
  62. package/src/components/sidebar/post-template/index.js +101 -0
  63. package/src/components/sidebar/post-template/style.scss +46 -0
  64. package/src/components/sidebar/post-visibility/style.scss +4 -4
  65. package/src/components/sidebar/settings-sidebar/index.js +0 -2
  66. package/src/components/start-page-options/index.js +46 -22
  67. package/src/editor.js +2 -2
  68. package/src/editor.native.js +2 -2
  69. package/src/store/selectors.js +5 -8
  70. package/src/style.scss +1 -1
  71. package/build/components/sidebar/template/actions.js +0 -172
  72. package/build/components/sidebar/template/actions.js.map +0 -1
  73. package/build/components/sidebar/template/index.js +0 -164
  74. package/build/components/sidebar/template/index.js.map +0 -1
  75. package/build-module/components/sidebar/template/actions.js +0 -158
  76. package/build-module/components/sidebar/template/actions.js.map +0 -1
  77. package/build-module/components/sidebar/template/index.js +0 -145
  78. package/build-module/components/sidebar/template/index.js.map +0 -1
  79. package/src/components/sidebar/template/actions.js +0 -206
  80. package/src/components/sidebar/template/index.js +0 -160
  81. package/src/components/sidebar/template/style.scss +0 -43
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/edit-post",
3
- "version": "6.8.0",
3
+ "version": "6.9.0",
4
4
  "description": "Edit Post module for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -27,31 +27,31 @@
27
27
  "react-native": "src/index",
28
28
  "dependencies": {
29
29
  "@babel/runtime": "^7.16.0",
30
- "@wordpress/a11y": "^3.11.0",
31
- "@wordpress/api-fetch": "^6.8.0",
32
- "@wordpress/block-editor": "^9.3.0",
33
- "@wordpress/block-library": "^7.8.0",
34
- "@wordpress/blocks": "^11.10.0",
35
- "@wordpress/components": "^19.13.0",
36
- "@wordpress/compose": "^5.9.0",
37
- "@wordpress/core-data": "^4.9.0",
38
- "@wordpress/data": "^6.11.0",
39
- "@wordpress/deprecated": "^3.11.0",
40
- "@wordpress/editor": "^12.10.0",
41
- "@wordpress/element": "^4.9.0",
42
- "@wordpress/hooks": "^3.11.0",
43
- "@wordpress/i18n": "^4.11.0",
44
- "@wordpress/icons": "^9.2.0",
45
- "@wordpress/interface": "^4.10.0",
46
- "@wordpress/keyboard-shortcuts": "^3.9.0",
47
- "@wordpress/keycodes": "^3.11.0",
48
- "@wordpress/media-utils": "^4.2.0",
49
- "@wordpress/notices": "^3.11.0",
50
- "@wordpress/plugins": "^4.9.0",
51
- "@wordpress/preferences": "^2.3.0",
52
- "@wordpress/url": "^3.12.0",
53
- "@wordpress/viewport": "^4.9.0",
54
- "@wordpress/warning": "^2.11.0",
30
+ "@wordpress/a11y": "^3.12.0",
31
+ "@wordpress/api-fetch": "^6.9.0",
32
+ "@wordpress/block-editor": "^9.4.0",
33
+ "@wordpress/block-library": "^7.9.0",
34
+ "@wordpress/blocks": "^11.11.0",
35
+ "@wordpress/components": "^19.14.0",
36
+ "@wordpress/compose": "^5.10.0",
37
+ "@wordpress/core-data": "^4.10.0",
38
+ "@wordpress/data": "^6.12.0",
39
+ "@wordpress/deprecated": "^3.12.0",
40
+ "@wordpress/editor": "^12.11.0",
41
+ "@wordpress/element": "^4.10.0",
42
+ "@wordpress/hooks": "^3.12.0",
43
+ "@wordpress/i18n": "^4.12.0",
44
+ "@wordpress/icons": "^9.3.0",
45
+ "@wordpress/interface": "^4.11.0",
46
+ "@wordpress/keyboard-shortcuts": "^3.10.0",
47
+ "@wordpress/keycodes": "^3.12.0",
48
+ "@wordpress/media-utils": "^4.3.0",
49
+ "@wordpress/notices": "^3.12.0",
50
+ "@wordpress/plugins": "^4.10.0",
51
+ "@wordpress/preferences": "^2.4.0",
52
+ "@wordpress/url": "^3.13.0",
53
+ "@wordpress/viewport": "^4.10.0",
54
+ "@wordpress/warning": "^2.12.0",
55
55
  "classnames": "^2.3.1",
56
56
  "lodash": "^4.17.21",
57
57
  "memize": "^1.1.0",
@@ -64,5 +64,5 @@
64
64
  "publishConfig": {
65
65
  "access": "public"
66
66
  },
67
- "gitHead": "48d5f37dfb52d2e77c8eeb662f9874cf141b8c6b"
67
+ "gitHead": "a80eeb62ec7cb1418b9915c277e084a29d6665e3"
68
68
  }
@@ -28,4 +28,12 @@ export const textFormattingShortcuts = [
28
28
  keyCombination: { modifier: 'primary', character: 'u' },
29
29
  description: __( 'Underline the selected text.' ),
30
30
  },
31
+ {
32
+ keyCombination: { modifier: 'access', character: 'd' },
33
+ description: __( 'Strikethrough the selected text.' ),
34
+ },
35
+ {
36
+ keyCombination: { modifier: 'access', character: 'x' },
37
+ description: __( 'Make the selected text inline code.' ),
38
+ },
31
39
  ];
@@ -82,6 +82,20 @@ exports[`KeyboardShortcutHelpModal should match snapshot when the modal is activ
82
82
  "modifier": "primary",
83
83
  },
84
84
  },
85
+ Object {
86
+ "description": "Strikethrough the selected text.",
87
+ "keyCombination": Object {
88
+ "character": "d",
89
+ "modifier": "access",
90
+ },
91
+ },
92
+ Object {
93
+ "description": "Make the selected text inline code.",
94
+ "keyCombination": Object {
95
+ "character": "x",
96
+ "modifier": "access",
97
+ },
98
+ },
85
99
  ]
86
100
  }
87
101
  title="Text formatting"
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Defines as extensibility slot for the Status & visibility panel.
2
+ * Defines as extensibility slot for the Summary panel.
3
3
  */
4
4
 
5
5
  /**
@@ -10,7 +10,7 @@ import { createSlotFill, PanelRow } from '@wordpress/components';
10
10
  export const { Fill, Slot } = createSlotFill( 'PluginPostStatusInfo' );
11
11
 
12
12
  /**
13
- * Renders a row in the Status & visibility panel of the Document sidebar.
13
+ * Renders a row in the Summary panel of the Document sidebar.
14
14
  * It should be noted that this is named and implemented around the function it serves
15
15
  * and not its location, which may change in future iterations.
16
16
  *
@@ -8,11 +8,14 @@ import {
8
8
  PostSchedule as PostScheduleForm,
9
9
  PostScheduleLabel,
10
10
  PostScheduleCheck,
11
+ usePostScheduleLabel,
11
12
  } from '@wordpress/editor';
12
13
 
13
- export function PostSchedule() {
14
+ export default function PostSchedule() {
14
15
  const anchorRef = useRef();
15
16
 
17
+ const fullLabel = usePostScheduleLabel( { full: true } );
18
+
16
19
  return (
17
20
  <PostScheduleCheck>
18
21
  <PanelRow className="edit-post-post-schedule" ref={ anchorRef }>
@@ -28,6 +31,7 @@ export function PostSchedule() {
28
31
  onClick={ onToggle }
29
32
  aria-expanded={ isOpen }
30
33
  variant="tertiary"
34
+ label={ fullLabel }
31
35
  >
32
36
  <PostScheduleLabel />
33
37
  </Button>
@@ -41,5 +45,3 @@ export function PostSchedule() {
41
45
  </PostScheduleCheck>
42
46
  );
43
47
  }
44
-
45
- export default PostSchedule;
@@ -2,17 +2,32 @@
2
2
  width: 100%;
3
3
  position: relative;
4
4
  justify-content: flex-start;
5
+ align-items: flex-start;
5
6
 
6
7
  span {
7
8
  display: block;
8
9
  width: 45%;
10
+ flex-shrink: 0;
11
+ padding: 6px 0;
9
12
  }
10
13
  }
11
14
 
12
15
  .components-button.edit-post-post-schedule__toggle {
13
- text-align: right;
16
+ text-align: left;
17
+ white-space: normal;
18
+ height: auto;
19
+
20
+ // This span is added by the Popover in Tooltip when no anchorRef is
21
+ // provided. We set its width to 0 so that it does not cause the button text
22
+ // to wrap to a new line when displaying the tooltip. A better fix would be
23
+ // to pass anchorRef and avoid the need for a span alltogether, which is
24
+ // what this PR allows us to do:
25
+ // https://github.com/WordPress/gutenberg/pull/41268.
26
+ span {
27
+ width: 0;
28
+ }
14
29
  }
15
30
 
16
- .edit-post-post-schedule__dialog .components-popover__content {
17
- padding: $grid-unit-20;
31
+ .edit-post-post-schedule__dialog .block-editor-publish-date-time-picker {
32
+ margin: $grid-unit-10;
18
33
  }
@@ -19,6 +19,7 @@ import PostFormat from '../post-format';
19
19
  import PostPendingStatus from '../post-pending-status';
20
20
  import PluginPostStatusInfo from '../plugin-post-status-info';
21
21
  import { store as editPostStore } from '../../../store';
22
+ import PostTemplate from '../post-template';
22
23
 
23
24
  /**
24
25
  * Module Constants
@@ -29,7 +30,7 @@ function PostStatus( { isOpened, onTogglePanel } ) {
29
30
  return (
30
31
  <PanelBody
31
32
  className="edit-post-post-status"
32
- title={ __( 'Status & visibility' ) }
33
+ title={ __( 'Summary' ) }
33
34
  opened={ isOpened }
34
35
  onToggle={ onTogglePanel }
35
36
  >
@@ -38,6 +39,7 @@ function PostStatus( { isOpened, onTogglePanel } ) {
38
39
  <>
39
40
  <PostVisibility />
40
41
  <PostSchedule />
42
+ <PostTemplate />
41
43
  <PostFormat />
42
44
  <PostSticky />
43
45
  <PostPendingStatus />
@@ -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 purpose of the template, e.g. "Full Width". 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,140 @@
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: canCreateTemplates && ! _isPostsPage,
54
+ canEdit:
55
+ canCreateTemplates &&
56
+ editorSettings.supportsTemplateMode &&
57
+ !! select( editPostStore ).getEditedPostTemplate(),
58
+ };
59
+ }, [] );
60
+
61
+ const options = useMemo(
62
+ () =>
63
+ Object.entries( {
64
+ ...availableTemplates,
65
+ ...Object.fromEntries(
66
+ ( fetchedTemplates ?? [] ).map( ( { slug, title } ) => [
67
+ slug,
68
+ title.rendered,
69
+ ] )
70
+ ),
71
+ } ).map( ( [ slug, title ] ) => ( { value: slug, label: title } ) ),
72
+ [ availableTemplates, fetchedTemplates ]
73
+ );
74
+
75
+ const selectedOption =
76
+ options.find( ( option ) => option.value === selectedTemplateSlug ) ??
77
+ options.find( ( option ) => ! option.value ); // The default option has '' value.
78
+
79
+ const { editPost } = useDispatch( editorStore );
80
+ const { __unstableSwitchToTemplateMode } = useDispatch( editPostStore );
81
+
82
+ const [ isCreateModalOpen, setIsCreateModalOpen ] = useState( false );
83
+
84
+ return (
85
+ <div className="edit-post-post-template__form">
86
+ <InspectorPopoverHeader
87
+ title={ __( 'Template' ) }
88
+ help={ __(
89
+ 'Templates define the way content is displayed when viewing your site.'
90
+ ) }
91
+ actions={
92
+ canCreate
93
+ ? [
94
+ {
95
+ icon: addTemplate,
96
+ label: __( 'Add template' ),
97
+ onClick: () => setIsCreateModalOpen( true ),
98
+ },
99
+ ]
100
+ : []
101
+ }
102
+ onClose={ onClose }
103
+ />
104
+ { isPostsPage ? (
105
+ <Notice
106
+ className="edit-post-post-template__notice"
107
+ status="warning"
108
+ isDismissible={ false }
109
+ >
110
+ { __( 'The posts page template cannot be changed.' ) }
111
+ </Notice>
112
+ ) : (
113
+ <SelectControl
114
+ hideLabelFromVision
115
+ label={ __( 'Template' ) }
116
+ value={ selectedOption?.value ?? '' }
117
+ options={ options }
118
+ onChange={ ( slug ) =>
119
+ editPost( { template: slug || '' } )
120
+ }
121
+ />
122
+ ) }
123
+ { canEdit && (
124
+ <p>
125
+ <Button
126
+ variant="link"
127
+ onClick={ () => __unstableSwitchToTemplateMode() }
128
+ >
129
+ { __( 'Edit template' ) }
130
+ </Button>
131
+ </p>
132
+ ) }
133
+ { isCreateModalOpen && (
134
+ <PostTemplateCreateModal
135
+ onClose={ () => setIsCreateModalOpen( false ) }
136
+ />
137
+ ) }
138
+ </div>
139
+ );
140
+ }
@@ -0,0 +1,101 @@
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
+ const canCreateTemplates =
35
+ select( coreStore ).canUser( 'create', 'templates' ) ?? false;
36
+ return canCreateTemplates;
37
+ }, [] );
38
+
39
+ if ( ! isVisible ) {
40
+ return null;
41
+ }
42
+
43
+ return (
44
+ <PanelRow className="edit-post-post-template" ref={ anchorRef }>
45
+ <span>{ __( 'Template' ) }</span>
46
+ <Dropdown
47
+ popoverProps={ { anchorRef } }
48
+ position="bottom left"
49
+ className="edit-post-post-template__dropdown"
50
+ contentClassName="edit-post-post-template__dialog"
51
+ renderToggle={ ( { isOpen, onToggle } ) => (
52
+ <PostTemplateToggle
53
+ isOpen={ isOpen }
54
+ onClick={ onToggle }
55
+ />
56
+ ) }
57
+ renderContent={ ( { onClose } ) => (
58
+ <PostTemplateForm onClose={ onClose } />
59
+ ) }
60
+ />
61
+ </PanelRow>
62
+ );
63
+ }
64
+
65
+ function PostTemplateToggle( { isOpen, onClick } ) {
66
+ const templateTitle = useSelect( ( select ) => {
67
+ const templateSlug =
68
+ select( editorStore ).getEditedPostAttribute( 'template' );
69
+
70
+ const settings = select( editorStore ).getEditorSettings();
71
+ if ( settings.availableTemplates[ templateSlug ] ) {
72
+ return settings.availableTemplates[ templateSlug ];
73
+ }
74
+
75
+ const template = select( coreStore )
76
+ .getEntityRecords( 'postType', 'wp_template', { per_page: -1 } )
77
+ ?.find( ( { slug } ) => slug === templateSlug );
78
+
79
+ return template?.title.rendered;
80
+ }, [] );
81
+
82
+ return (
83
+ <Button
84
+ className="edit-post-post-template__toggle"
85
+ variant="tertiary"
86
+ aria-expanded={ isOpen }
87
+ aria-label={
88
+ templateTitle
89
+ ? sprintf(
90
+ // translators: %s: Name of the currently selected template.
91
+ __( 'Select template: %s' ),
92
+ templateTitle
93
+ )
94
+ : __( 'Select template' )
95
+ }
96
+ onClick={ onClick }
97
+ >
98
+ { templateTitle ?? __( '(none)' ) }
99
+ </Button>
100
+ );
101
+ }
@@ -0,0 +1,46 @@
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-modal {
33
+ .components-modal__header {
34
+ border-bottom: none;
35
+ }
36
+
37
+ .components-modal__content::before {
38
+ margin-bottom: $grid-unit-05;
39
+ }
40
+ }
41
+
42
+ .edit-post-post-template__create-form {
43
+ @include break-medium() {
44
+ width: $grid-unit * 40;
45
+ }
46
+ }
@@ -8,8 +8,8 @@
8
8
  }
9
9
  }
10
10
 
11
- .edit-post-post-visibility__dialog .components-popover__content {
12
- // sidebar width - padding - horizontal borders
13
- width: $sidebar-width - $grid-unit-20 - $border-width * 2;
14
- padding: $grid-unit-20;
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
  }
@@ -25,7 +25,6 @@ import PageAttributes from '../page-attributes';
25
25
  import MetaBoxes from '../../meta-boxes';
26
26
  import PluginDocumentSettingPanel from '../plugin-document-setting-panel';
27
27
  import PluginSidebarEditPost from '../plugin-sidebar';
28
- import Template from '../template';
29
28
  import TemplateSummary from '../template-summary';
30
29
  import { __ } from '@wordpress/i18n';
31
30
  import { useSelect } from '@wordpress/data';
@@ -86,7 +85,6 @@ const SettingsSidebar = () => {
86
85
  { ! isTemplateMode && sidebarName === 'edit-post/document' && (
87
86
  <>
88
87
  <PostStatus />
89
- <Template />
90
88
  <PluginDocumentSettingPanel.Slot />
91
89
  <LastRevision />
92
90
  <PostLink />