@wordpress/editor 12.5.4 → 12.7.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 (36) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/components/post-featured-image/index.js +84 -41
  3. package/build/components/post-featured-image/index.js.map +1 -1
  4. package/build/components/post-text-editor/index.js +11 -0
  5. package/build/components/post-text-editor/index.js.map +1 -1
  6. package/build/components/post-title/index.js +13 -2
  7. package/build/components/post-title/index.js.map +1 -1
  8. package/build/components/post-visibility/index.js +132 -167
  9. package/build/components/post-visibility/index.js.map +1 -1
  10. package/build/components/post-visibility/label.js +5 -22
  11. package/build/components/post-visibility/label.js.map +1 -1
  12. package/build/components/post-visibility/utils.js +14 -13
  13. package/build/components/post-visibility/utils.js.map +1 -1
  14. package/build-module/components/post-featured-image/index.js +86 -42
  15. package/build-module/components/post-featured-image/index.js.map +1 -1
  16. package/build-module/components/post-text-editor/index.js +12 -1
  17. package/build-module/components/post-text-editor/index.js.map +1 -1
  18. package/build-module/components/post-title/index.js +12 -2
  19. package/build-module/components/post-title/index.js.map +1 -1
  20. package/build-module/components/post-visibility/index.js +132 -166
  21. package/build-module/components/post-visibility/index.js.map +1 -1
  22. package/build-module/components/post-visibility/label.js +5 -20
  23. package/build-module/components/post-visibility/label.js.map +1 -1
  24. package/build-module/components/post-visibility/utils.js +14 -13
  25. package/build-module/components/post-visibility/utils.js.map +1 -1
  26. package/build-style/style-rtl.css +42 -51
  27. package/build-style/style.css +42 -51
  28. package/package.json +28 -27
  29. package/src/components/autosave-monitor/test/index.js +3 -0
  30. package/src/components/post-featured-image/index.js +102 -69
  31. package/src/components/post-text-editor/index.js +14 -1
  32. package/src/components/post-title/index.js +16 -2
  33. package/src/components/post-visibility/index.js +130 -150
  34. package/src/components/post-visibility/label.js +6 -15
  35. package/src/components/post-visibility/style.scss +25 -20
  36. package/src/components/post-visibility/utils.js +7 -12
@@ -2,13 +2,15 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { __ } from '@wordpress/i18n';
5
- import { Component } from '@wordpress/element';
5
+ import { useState } from '@wordpress/element';
6
6
  import {
7
7
  VisuallyHidden,
8
8
  __experimentalConfirmDialog as ConfirmDialog,
9
+ Button,
9
10
  } from '@wordpress/components';
10
- import { withInstanceId, compose } from '@wordpress/compose';
11
- import { withSelect, withDispatch } from '@wordpress/data';
11
+ import { useInstanceId } from '@wordpress/compose';
12
+ import { useSelect, useDispatch } from '@wordpress/data';
13
+ import { close as closeIcon } from '@wordpress/icons';
12
14
 
13
15
  /**
14
16
  * Internal dependencies
@@ -16,172 +18,150 @@ import { withSelect, withDispatch } from '@wordpress/data';
16
18
  import { visibilityOptions } from './utils';
17
19
  import { store as editorStore } from '../../store';
18
20
 
19
- export class PostVisibility extends Component {
20
- constructor( props ) {
21
- super( ...arguments );
21
+ export default function PostVisibility( { onClose } ) {
22
+ const instanceId = useInstanceId( PostVisibility );
22
23
 
23
- this.setPublic = this.setPublic.bind( this );
24
- this.setPrivate = this.setPrivate.bind( this );
25
- this.setPasswordProtected = this.setPasswordProtected.bind( this );
26
- this.updatePassword = this.updatePassword.bind( this );
24
+ const { status, visibility, password } = useSelect( ( select ) => ( {
25
+ status: select( editorStore ).getEditedPostAttribute( 'status' ),
26
+ visibility: select( editorStore ).getEditedPostVisibility(),
27
+ password: select( editorStore ).getEditedPostAttribute( 'password' ),
28
+ } ) );
27
29
 
28
- this.state = {
29
- hasPassword: !! props.password,
30
- showPrivateConfirmDialog: false,
31
- };
32
- }
30
+ const { editPost, savePost } = useDispatch( editorStore );
33
31
 
34
- setPublic() {
35
- const { visibility, onUpdateVisibility, status } = this.props;
32
+ const [ hasPassword, setHasPassword ] = useState( !! password );
33
+ const [ showPrivateConfirmDialog, setShowPrivateConfirmDialog ] = useState(
34
+ false
35
+ );
36
36
 
37
- onUpdateVisibility( visibility === 'private' ? 'draft' : status );
38
- this.setState( { hasPassword: false } );
39
- }
40
-
41
- setPrivate() {
42
- this.setState( { showPrivateConfirmDialog: true } );
43
- }
44
-
45
- confirmPrivate = () => {
46
- const { onUpdateVisibility, onSave } = this.props;
47
-
48
- onUpdateVisibility( 'private' );
49
- this.setState( {
50
- hasPassword: false,
51
- showPrivateConfirmDialog: false,
37
+ const setPublic = () => {
38
+ editPost( {
39
+ status: visibility === 'private' ? 'draft' : status,
40
+ password: '',
52
41
  } );
53
- onSave();
42
+ setHasPassword( false );
54
43
  };
55
44
 
56
- handleDialogCancel = () => {
57
- this.setState( { showPrivateConfirmDialog: false } );
45
+ const setPrivate = () => {
46
+ setShowPrivateConfirmDialog( true );
58
47
  };
59
48
 
60
- setPasswordProtected() {
61
- const { visibility, onUpdateVisibility, status, password } = this.props;
62
-
63
- onUpdateVisibility(
64
- visibility === 'private' ? 'draft' : status,
65
- password || ''
66
- );
67
- this.setState( { hasPassword: true } );
68
- }
49
+ const confirmPrivate = () => {
50
+ editPost( { status: 'private', password: '' } );
51
+ setHasPassword( false );
52
+ setShowPrivateConfirmDialog( false );
53
+ savePost();
54
+ };
69
55
 
70
- updatePassword( event ) {
71
- const { status, onUpdateVisibility } = this.props;
72
- onUpdateVisibility( status, event.target.value );
73
- }
56
+ const handleDialogCancel = () => {
57
+ setShowPrivateConfirmDialog( false );
58
+ };
74
59
 
75
- render() {
76
- const { visibility, password, instanceId } = this.props;
60
+ const setPasswordProtected = () => {
61
+ editPost( {
62
+ status: visibility === 'private' ? 'draft' : status,
63
+ password: password || '',
64
+ } );
65
+ setHasPassword( true );
66
+ };
77
67
 
78
- const visibilityHandlers = {
79
- public: {
80
- onSelect: this.setPublic,
81
- checked: visibility === 'public' && ! this.state.hasPassword,
82
- },
83
- private: {
84
- onSelect: this.setPrivate,
85
- checked: visibility === 'private',
86
- },
87
- password: {
88
- onSelect: this.setPasswordProtected,
89
- checked: this.state.hasPassword,
90
- },
91
- };
68
+ const updatePassword = ( event ) => {
69
+ editPost( { password: event.target.value } );
70
+ };
92
71
 
93
- return [
94
- <fieldset
95
- key="visibility-selector"
96
- className="editor-post-visibility__dialog-fieldset"
97
- >
98
- <legend className="editor-post-visibility__dialog-legend">
99
- { __( 'Post Visibility' ) }
72
+ return (
73
+ <>
74
+ <Button
75
+ className="editor-post-visibility__close"
76
+ isSmall
77
+ icon={ closeIcon }
78
+ onClick={ onClose }
79
+ />
80
+ <fieldset className="editor-post-visibility__fieldset">
81
+ <legend className="editor-post-visibility__legend">
82
+ { __( 'Visibility' ) }
100
83
  </legend>
101
- { visibilityOptions.map( ( { value, label, info } ) => (
102
- <div
103
- key={ value }
104
- className="editor-post-visibility__choice"
105
- >
84
+ <p className="editor-post-visibility__description">
85
+ { __( 'Control how this post is viewed.' ) }
86
+ </p>
87
+ <PostVisibilityChoice
88
+ instanceId={ instanceId }
89
+ value="public"
90
+ label={ visibilityOptions.public.label }
91
+ info={ visibilityOptions.public.info }
92
+ checked={ visibility === 'public' && ! hasPassword }
93
+ onChange={ setPublic }
94
+ />
95
+ <PostVisibilityChoice
96
+ instanceId={ instanceId }
97
+ value="private"
98
+ label={ visibilityOptions.private.label }
99
+ info={ visibilityOptions.private.info }
100
+ checked={ visibility === 'private' }
101
+ onChange={ setPrivate }
102
+ />
103
+ <PostVisibilityChoice
104
+ instanceId={ instanceId }
105
+ value="password"
106
+ label={ visibilityOptions.password.label }
107
+ info={ visibilityOptions.password.info }
108
+ checked={ hasPassword }
109
+ onChange={ setPasswordProtected }
110
+ />
111
+ { hasPassword && (
112
+ <div className="editor-post-visibility__password">
113
+ <VisuallyHidden
114
+ as="label"
115
+ htmlFor={ `editor-post-visibility__password-input-${ instanceId }` }
116
+ >
117
+ { __( 'Create password' ) }
118
+ </VisuallyHidden>
106
119
  <input
107
- type="radio"
108
- name={ `editor-post-visibility__setting-${ instanceId }` }
109
- value={ value }
110
- onChange={ visibilityHandlers[ value ].onSelect }
111
- checked={ visibilityHandlers[ value ].checked }
112
- id={ `editor-post-${ value }-${ instanceId }` }
113
- aria-describedby={ `editor-post-${ value }-${ instanceId }-description` }
114
- className="editor-post-visibility__dialog-radio"
120
+ className="editor-post-visibility__password-input"
121
+ id={ `editor-post-visibility__password-input-${ instanceId }` }
122
+ type="text"
123
+ onChange={ updatePassword }
124
+ value={ password }
125
+ placeholder={ __( 'Use a secure password' ) }
115
126
  />
116
- <label
117
- htmlFor={ `editor-post-${ value }-${ instanceId }` }
118
- className="editor-post-visibility__dialog-label"
119
- >
120
- { label }
121
- </label>
122
- {
123
- <p
124
- id={ `editor-post-${ value }-${ instanceId }-description` }
125
- className="editor-post-visibility__dialog-info"
126
- >
127
- { info }
128
- </p>
129
- }
130
127
  </div>
131
- ) ) }
132
- </fieldset>,
133
- this.state.hasPassword && (
134
- <div
135
- className="editor-post-visibility__dialog-password"
136
- key="password-selector"
137
- >
138
- <VisuallyHidden
139
- as="label"
140
- htmlFor={ `editor-post-visibility__dialog-password-input-${ instanceId }` }
141
- >
142
- { __( 'Create password' ) }
143
- </VisuallyHidden>
144
- <input
145
- className="editor-post-visibility__dialog-password-input"
146
- id={ `editor-post-visibility__dialog-password-input-${ instanceId }` }
147
- type="text"
148
- onChange={ this.updatePassword }
149
- value={ password }
150
- placeholder={ __( 'Use a secure password' ) }
151
- />
152
- </div>
153
- ),
128
+ ) }
129
+ </fieldset>
154
130
  <ConfirmDialog
155
- key="private-publish-confirmation"
156
- isOpen={ this.state.showPrivateConfirmDialog }
157
- onConfirm={ this.confirmPrivate }
158
- onCancel={ this.handleDialogCancel }
131
+ isOpen={ showPrivateConfirmDialog }
132
+ onConfirm={ confirmPrivate }
133
+ onCancel={ handleDialogCancel }
159
134
  >
160
135
  { __( 'Would you like to privately publish this post now?' ) }
161
- </ConfirmDialog>,
162
- ];
163
- }
136
+ </ConfirmDialog>
137
+ </>
138
+ );
164
139
  }
165
140
 
166
- export default compose( [
167
- withSelect( ( select ) => {
168
- const { getEditedPostAttribute, getEditedPostVisibility } = select(
169
- editorStore
170
- );
171
- return {
172
- status: getEditedPostAttribute( 'status' ),
173
- visibility: getEditedPostVisibility(),
174
- password: getEditedPostAttribute( 'password' ),
175
- };
176
- } ),
177
- withDispatch( ( dispatch ) => {
178
- const { savePost, editPost } = dispatch( editorStore );
179
- return {
180
- onSave: savePost,
181
- onUpdateVisibility( status, password = '' ) {
182
- editPost( { status, password } );
183
- },
184
- };
185
- } ),
186
- withInstanceId,
187
- ] )( PostVisibility );
141
+ function PostVisibilityChoice( { instanceId, value, label, info, ...props } ) {
142
+ return (
143
+ <div className="editor-post-visibility__choice">
144
+ <input
145
+ type="radio"
146
+ name={ `editor-post-visibility__setting-${ instanceId }` }
147
+ value={ value }
148
+ id={ `editor-post-${ value }-${ instanceId }` }
149
+ aria-describedby={ `editor-post-${ value }-${ instanceId }-description` }
150
+ className="editor-post-visibility__radio"
151
+ { ...props }
152
+ />
153
+ <label
154
+ htmlFor={ `editor-post-${ value }-${ instanceId }` }
155
+ className="editor-post-visibility__label"
156
+ >
157
+ { label }
158
+ </label>
159
+ <p
160
+ id={ `editor-post-${ value }-${ instanceId }-description` }
161
+ className="editor-post-visibility__info"
162
+ >
163
+ { info }
164
+ </p>
165
+ </div>
166
+ );
167
+ }
@@ -1,12 +1,7 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { find } from 'lodash';
5
-
6
1
  /**
7
2
  * WordPress dependencies
8
3
  */
9
- import { withSelect } from '@wordpress/data';
4
+ import { useSelect } from '@wordpress/data';
10
5
 
11
6
  /**
12
7
  * Internal dependencies
@@ -14,13 +9,9 @@ import { withSelect } from '@wordpress/data';
14
9
  import { visibilityOptions } from './utils';
15
10
  import { store as editorStore } from '../../store';
16
11
 
17
- function PostVisibilityLabel( { visibility } ) {
18
- const getVisibilityLabel = () =>
19
- find( visibilityOptions, { value: visibility } ).label;
20
-
21
- return getVisibilityLabel( visibility );
12
+ export default function PostVisibilityLabel() {
13
+ const visibility = useSelect( ( select ) =>
14
+ select( editorStore ).getEditedPostVisibility()
15
+ );
16
+ return visibilityOptions[ visibility ]?.label;
22
17
  }
23
-
24
- export default withSelect( ( select ) => ( {
25
- visibility: select( editorStore ).getEditedPostVisibility(),
26
- } ) )( PostVisibilityLabel );
@@ -1,39 +1,44 @@
1
- .edit-post-post-visibility__dialog,
2
- .editor-post-visibility__dialog-fieldset {
3
- padding: $grid-unit-05;
4
- padding-top: 0;
1
+ .editor-post-visibility__close {
2
+ position: absolute;
3
+ right: $grid-unit-20;
4
+ top: $grid-unit-20;
5
+ }
6
+
7
+ .editor-post-visibility__fieldset {
8
+ padding: $grid-unit-10;
5
9
 
6
- .editor-post-visibility__dialog-legend {
10
+ .editor-post-visibility__legend {
7
11
  font-weight: 600;
8
- margin-bottom: 1em;
12
+ padding: 1em 0 0 0;
13
+ }
14
+
15
+ .editor-post-visibility__description {
9
16
  margin-top: 0.5em;
10
- padding: 0;
11
17
  }
12
18
 
13
- .editor-post-visibility__dialog-radio[type="radio"] {
19
+ .editor-post-visibility__radio[type="radio"] {
14
20
  @include radio-control;
15
21
  margin-top: 2px;
16
22
  }
17
23
 
18
- .editor-post-visibility__dialog-label {
19
- font-weight: 600;
20
- }
24
+ .editor-post-visibility__info {
25
+ color: $gray-700;
26
+ margin-left: $grid-unit-15 + $radio-input-size-sm;
27
+ margin-top: 0.5em;
21
28
 
22
- .editor-post-visibility__dialog-info {
23
- margin-top: 0;
24
- margin-left: $grid-unit-40;
29
+ @include break-small {
30
+ margin-left: $grid-unit-15 + $radio-input-size;
31
+ }
25
32
  }
26
33
 
27
34
  // Remove bottom margin on the last label only.
28
- .editor-post-visibility__choice:last-child .editor-post-visibility__dialog-info {
35
+ .editor-post-visibility__choice:last-child .editor-post-visibility__info {
29
36
  margin-bottom: 0;
30
37
  }
31
- }
32
38
 
33
- .editor-post-visibility__dialog-password {
34
- .editor-post-visibility__dialog-password-input[type="text"] {
39
+ .editor-post-visibility__password .editor-post-visibility__password-input[type="text"] {
35
40
  @include input-control;
36
- margin-left: $grid-unit * 4.5;
37
- margin-top: $grid-unit-10;
41
+ margin-left: $grid-unit * 4;
42
+ width: calc(100% - #{$grid-unit * 4});
38
43
  }
39
44
  }
@@ -3,22 +3,17 @@
3
3
  */
4
4
  import { __ } from '@wordpress/i18n';
5
5
 
6
- export const visibilityOptions = [
7
- {
8
- value: 'public',
6
+ export const visibilityOptions = {
7
+ public: {
9
8
  label: __( 'Public' ),
10
9
  info: __( 'Visible to everyone.' ),
11
10
  },
12
- {
13
- value: 'private',
11
+ private: {
14
12
  label: __( 'Private' ),
15
13
  info: __( 'Only visible to site admins and editors.' ),
16
14
  },
17
- {
18
- value: 'password',
19
- label: __( 'Password Protected' ),
20
- info: __(
21
- 'Protected with a password you choose. Only those with the password can view this post.'
22
- ),
15
+ password: {
16
+ label: __( 'Password protected' ),
17
+ info: __( 'Only those with the password can view this post.' ),
23
18
  },
24
- ];
19
+ };