@wordpress/editor 14.19.1 → 14.20.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 (79) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/commands/index.js +1 -1
  3. package/build/components/commands/index.js.map +1 -1
  4. package/build/components/post-actions/actions.js +10 -8
  5. package/build/components/post-actions/actions.js.map +1 -1
  6. package/build/components/post-publish-panel/maybe-category-panel.js +19 -3
  7. package/build/components/post-publish-panel/maybe-category-panel.js.map +1 -1
  8. package/build/components/post-publish-panel/maybe-tags-panel.js +16 -6
  9. package/build/components/post-publish-panel/maybe-tags-panel.js.map +1 -1
  10. package/build/components/post-status/index.js +1 -1
  11. package/build/components/post-status/index.js.map +1 -1
  12. package/build/components/post-sticky/index.js +1 -1
  13. package/build/components/post-sticky/index.js.map +1 -1
  14. package/build/components/post-template/hooks.js +6 -5
  15. package/build/components/post-template/hooks.js.map +1 -1
  16. package/build/components/post-template/swap-template-button.js +2 -3
  17. package/build/components/post-template/swap-template-button.js.map +1 -1
  18. package/build/components/post-visibility/index.js +39 -109
  19. package/build/components/post-visibility/index.js.map +1 -1
  20. package/build/components/post-visibility/label.js +2 -2
  21. package/build/components/post-visibility/label.js.map +1 -1
  22. package/build/components/post-visibility/utils.js +14 -15
  23. package/build/components/post-visibility/utils.js.map +1 -1
  24. package/build/components/provider/index.js +7 -4
  25. package/build/components/provider/index.js.map +1 -1
  26. package/build-module/components/commands/index.js +1 -1
  27. package/build-module/components/commands/index.js.map +1 -1
  28. package/build-module/components/post-actions/actions.js +10 -8
  29. package/build-module/components/post-actions/actions.js.map +1 -1
  30. package/build-module/components/post-publish-panel/maybe-category-panel.js +19 -3
  31. package/build-module/components/post-publish-panel/maybe-category-panel.js.map +1 -1
  32. package/build-module/components/post-publish-panel/maybe-tags-panel.js +16 -6
  33. package/build-module/components/post-publish-panel/maybe-tags-panel.js.map +1 -1
  34. package/build-module/components/post-status/index.js +1 -1
  35. package/build-module/components/post-status/index.js.map +1 -1
  36. package/build-module/components/post-sticky/index.js +1 -1
  37. package/build-module/components/post-sticky/index.js.map +1 -1
  38. package/build-module/components/post-template/hooks.js +6 -5
  39. package/build-module/components/post-template/hooks.js.map +1 -1
  40. package/build-module/components/post-template/swap-template-button.js +2 -3
  41. package/build-module/components/post-template/swap-template-button.js.map +1 -1
  42. package/build-module/components/post-visibility/index.js +41 -111
  43. package/build-module/components/post-visibility/index.js.map +1 -1
  44. package/build-module/components/post-visibility/label.js +3 -3
  45. package/build-module/components/post-visibility/label.js.map +1 -1
  46. package/build-module/components/post-visibility/utils.js +13 -14
  47. package/build-module/components/post-visibility/utils.js.map +1 -1
  48. package/build-module/components/provider/index.js +7 -4
  49. package/build-module/components/provider/index.js.map +1 -1
  50. package/build-style/style-rtl.css +2 -137
  51. package/build-style/style.css +2 -137
  52. package/build-types/components/post-actions/actions.d.ts.map +1 -1
  53. package/build-types/components/post-publish-panel/maybe-category-panel.d.ts.map +1 -1
  54. package/build-types/components/post-publish-panel/maybe-tags-panel.d.ts.map +1 -1
  55. package/build-types/components/post-template/hooks.d.ts.map +1 -1
  56. package/build-types/components/post-template/swap-template-button.d.ts +1 -1
  57. package/build-types/components/post-template/swap-template-button.d.ts.map +1 -1
  58. package/build-types/components/post-visibility/index.d.ts.map +1 -1
  59. package/build-types/components/post-visibility/label.d.ts.map +1 -1
  60. package/build-types/components/post-visibility/utils.d.ts +5 -20
  61. package/build-types/components/post-visibility/utils.d.ts.map +1 -1
  62. package/build-types/components/provider/index.d.ts.map +1 -1
  63. package/package.json +37 -37
  64. package/src/components/autocompleters/style.scss +2 -3
  65. package/src/components/commands/index.js +1 -1
  66. package/src/components/post-actions/actions.js +13 -8
  67. package/src/components/post-publish-panel/maybe-category-panel.js +20 -5
  68. package/src/components/post-publish-panel/maybe-tags-panel.js +39 -22
  69. package/src/components/post-status/index.js +1 -1
  70. package/src/components/post-sticky/index.js +1 -1
  71. package/src/components/post-template/hooks.js +12 -8
  72. package/src/components/post-template/swap-template-button.js +6 -4
  73. package/src/components/post-visibility/index.js +41 -118
  74. package/src/components/post-visibility/label.js +7 -4
  75. package/src/components/post-visibility/utils.js +11 -8
  76. package/src/components/provider/index.js +9 -4
  77. package/src/style.scss +0 -1
  78. package/tsconfig.tsbuildinfo +1 -1
  79. package/src/components/post-visibility/style.scss +0 -27
@@ -34,28 +34,45 @@ const TagsPanel = () => {
34
34
  };
35
35
 
36
36
  const MaybeTagsPanel = () => {
37
- const { hasTags, isPostTypeSupported } = useSelect( ( select ) => {
38
- const postType = select( editorStore ).getCurrentPostType();
39
- const tagsTaxonomy = select( coreStore ).getEntityRecord(
40
- 'root',
41
- 'taxonomy',
42
- 'post_tag'
43
- );
44
- const _isPostTypeSupported = tagsTaxonomy?.types?.includes( postType );
45
- const areTagsFetched = tagsTaxonomy !== undefined;
46
- const tags =
47
- tagsTaxonomy &&
48
- select( editorStore ).getEditedPostAttribute(
49
- tagsTaxonomy.rest_base
37
+ const { postHasTags, siteHasTags, isPostTypeSupported } = useSelect(
38
+ ( select ) => {
39
+ const postType = select( editorStore ).getCurrentPostType();
40
+ const tagsTaxonomy = select( coreStore ).getEntityRecord(
41
+ 'root',
42
+ 'taxonomy',
43
+ 'post_tag'
50
44
  );
51
- return {
52
- hasTags: !! tags?.length,
53
- isPostTypeSupported: areTagsFetched && _isPostTypeSupported,
54
- };
55
- }, [] );
56
- const [ hadTagsWhenOpeningThePanel ] = useState( hasTags );
45
+ const _isPostTypeSupported =
46
+ tagsTaxonomy?.types?.includes( postType );
47
+ const areTagsFetched = tagsTaxonomy !== undefined;
48
+ const tags =
49
+ tagsTaxonomy &&
50
+ select( editorStore ).getEditedPostAttribute(
51
+ tagsTaxonomy.rest_base
52
+ );
53
+ const siteTags = _isPostTypeSupported
54
+ ? !! select( coreStore ).getEntityRecords(
55
+ 'taxonomy',
56
+ 'post_tag',
57
+ { per_page: 1 }
58
+ )?.length
59
+ : false;
57
60
 
58
- if ( ! isPostTypeSupported ) {
61
+ return {
62
+ postHasTags: !! tags?.length,
63
+ siteHasTags: siteTags,
64
+ isPostTypeSupported: areTagsFetched && _isPostTypeSupported,
65
+ };
66
+ },
67
+ []
68
+ );
69
+ const [ hadTagsWhenOpeningThePanel ] = useState( postHasTags );
70
+
71
+ /**
72
+ * We only want to show the tag panel if the post type supports
73
+ * tags and the site has tags.
74
+ */
75
+ if ( ! isPostTypeSupported || ! siteHasTags ) {
59
76
  return null;
60
77
  }
61
78
 
@@ -63,9 +80,9 @@ const MaybeTagsPanel = () => {
63
80
  * We only want to show the tag panel if the post didn't have
64
81
  * any tags when the user hit the Publish button.
65
82
  *
66
- * We can't use the prop.hasTags because it'll change to true
83
+ * We can't use the prop.postHasTags because it'll change to true
67
84
  * if the user adds a new tag within the pre-publish panel.
68
- * This would force a re-render and a new prop.hasTags check,
85
+ * This would force a re-render and a new prop.postHasTags check,
69
86
  * hiding this panel and keeping the user from adding
70
87
  * more than one tag.
71
88
  */
@@ -230,7 +230,7 @@ export default function PostStatus() {
230
230
  'Password protected'
231
231
  ) }
232
232
  help={ __(
233
- 'Only visible to those who know the password'
233
+ 'Only visible to those who know the password.'
234
234
  ) }
235
235
  checked={ showPassword }
236
236
  onChange={
@@ -29,7 +29,7 @@ export default function PostSticky() {
29
29
  <CheckboxControl
30
30
  className="editor-post-sticky__checkbox-control"
31
31
  label={ __( 'Sticky' ) }
32
- help={ __( 'Pin this post to the top of the blog' ) }
32
+ help={ __( 'Pin this post to the top of the blog.' ) }
33
33
  checked={ postSticky }
34
34
  onChange={ () => editPost( { sticky: ! postSticky } ) }
35
35
  __nextHasNoMarginBottom
@@ -31,17 +31,21 @@ export function useAllowSwitchingTemplates() {
31
31
  } )
32
32
  ? getEntityRecord( 'root', 'site' )
33
33
  : undefined;
34
- const templates = getEntityRecords( 'postType', 'wp_template', {
35
- per_page: -1,
36
- } );
34
+
37
35
  const isPostsPage = +postId === siteSettings?.page_for_posts;
36
+ const isFrontPage =
37
+ postType === 'page' && +postId === siteSettings?.page_on_front;
38
38
  // If current page is set front page or posts page, we also need
39
39
  // to check if the current theme has a template for it. If not
40
- const isFrontPage =
41
- postType === 'page' &&
42
- +postId === siteSettings?.page_on_front &&
43
- templates?.some( ( { slug } ) => slug === 'front-page' );
44
- return ! isPostsPage && ! isFrontPage;
40
+ const templates = isFrontPage
41
+ ? getEntityRecords( 'postType', 'wp_template', {
42
+ per_page: -1,
43
+ } )
44
+ : [];
45
+ const hasFrontPage =
46
+ isFrontPage &&
47
+ !! templates?.some( ( { slug } ) => slug === 'front-page' );
48
+ return ! isPostsPage && ! hasFrontPage;
45
49
  },
46
50
  [ postId, postType ]
47
51
  );
@@ -20,9 +20,7 @@ export default function SwapTemplateButton( { onClick } ) {
20
20
  const { postType, postId } = useEditedPostContext();
21
21
  const availableTemplates = useAvailableTemplates( postType );
22
22
  const { editEntityRecord } = useDispatch( coreStore );
23
- if ( ! availableTemplates?.length ) {
24
- return null;
25
- }
23
+
26
24
  const onTemplateSelect = async ( template ) => {
27
25
  editEntityRecord(
28
26
  'postType',
@@ -36,7 +34,11 @@ export default function SwapTemplateButton( { onClick } ) {
36
34
  };
37
35
  return (
38
36
  <>
39
- <MenuItem onClick={ () => setShowModal( true ) }>
37
+ <MenuItem
38
+ disabled={ ! availableTemplates?.length }
39
+ accessibleWhenDisabled
40
+ onClick={ () => setShowModal( true ) }
41
+ >
40
42
  { __( 'Change template' ) }
41
43
  </MenuItem>
42
44
  { showModal && (
@@ -4,8 +4,9 @@
4
4
  import { __ } from '@wordpress/i18n';
5
5
  import { useState } from '@wordpress/element';
6
6
  import {
7
- VisuallyHidden,
8
- __experimentalConfirmDialog as ConfirmDialog,
7
+ TextControl,
8
+ RadioControl,
9
+ __experimentalVStack as VStack,
9
10
  } from '@wordpress/components';
10
11
  import { useInstanceId } from '@wordpress/compose';
11
12
  import { useSelect, useDispatch } from '@wordpress/data';
@@ -14,7 +15,7 @@ import { __experimentalInspectorPopoverHeader as InspectorPopoverHeader } from '
14
15
  /**
15
16
  * Internal dependencies
16
17
  */
17
- import { visibilityOptions } from './utils';
18
+ import { VISIBILITY_OPTIONS } from './utils';
18
19
  import { store as editorStore } from '../../store';
19
20
 
20
21
  /**
@@ -33,45 +34,29 @@ export default function PostVisibility( { onClose } ) {
33
34
  password: select( editorStore ).getEditedPostAttribute( 'password' ),
34
35
  } ) );
35
36
 
36
- const { editPost, savePost } = useDispatch( editorStore );
37
+ const { editPost } = useDispatch( editorStore );
37
38
 
38
39
  const [ hasPassword, setHasPassword ] = useState( !! password );
39
- const [ showPrivateConfirmDialog, setShowPrivateConfirmDialog ] =
40
- useState( false );
41
40
 
42
- const setPublic = () => {
43
- editPost( {
44
- status: visibility === 'private' ? 'draft' : status,
45
- password: '',
46
- } );
47
- setHasPassword( false );
48
- };
49
-
50
- const setPrivate = () => {
51
- setShowPrivateConfirmDialog( true );
52
- };
53
-
54
- const confirmPrivate = () => {
55
- editPost( { status: 'private', password: '' } );
56
- setHasPassword( false );
57
- setShowPrivateConfirmDialog( false );
58
- savePost();
59
- };
60
-
61
- const handleDialogCancel = () => {
62
- setShowPrivateConfirmDialog( false );
63
- };
41
+ function updateVisibility( value ) {
42
+ const nextValues = {
43
+ public: {
44
+ status: visibility === 'private' ? 'draft' : status,
45
+ password: '',
46
+ },
47
+ private: { status: 'private', password: '' },
48
+ password: {
49
+ status: visibility === 'private' ? 'draft' : status,
50
+ password: password || '',
51
+ },
52
+ };
64
53
 
65
- const setPasswordProtected = () => {
66
- editPost( {
67
- status: visibility === 'private' ? 'draft' : status,
68
- password: password || '',
69
- } );
70
- setHasPassword( true );
71
- };
54
+ editPost( nextValues[ value ] );
55
+ setHasPassword( value === 'password' );
56
+ }
72
57
 
73
- const updatePassword = ( event ) => {
74
- editPost( { password: event.target.value } );
58
+ const updatePassword = ( value ) => {
59
+ editPost( { password: value } );
75
60
  };
76
61
 
77
62
  return (
@@ -81,90 +66,28 @@ export default function PostVisibility( { onClose } ) {
81
66
  help={ __( 'Control how this post is viewed.' ) }
82
67
  onClose={ onClose }
83
68
  />
84
- <fieldset className="editor-post-visibility__fieldset">
85
- <VisuallyHidden as="legend">
86
- { __( 'Visibility' ) }
87
- </VisuallyHidden>
88
- <PostVisibilityChoice
89
- instanceId={ instanceId }
90
- value="public"
91
- label={ visibilityOptions.public.label }
92
- info={ visibilityOptions.public.info }
93
- checked={ visibility === 'public' && ! hasPassword }
94
- onChange={ setPublic }
95
- />
96
- <PostVisibilityChoice
97
- instanceId={ instanceId }
98
- value="private"
99
- label={ visibilityOptions.private.label }
100
- info={ visibilityOptions.private.info }
101
- checked={ visibility === 'private' }
102
- onChange={ setPrivate }
103
- />
104
- <PostVisibilityChoice
105
- instanceId={ instanceId }
106
- value="password"
107
- label={ visibilityOptions.password.label }
108
- info={ visibilityOptions.password.info }
109
- checked={ hasPassword }
110
- onChange={ setPasswordProtected }
69
+ <VStack spacing={ 4 }>
70
+ <RadioControl
71
+ label={ __( 'Visibility' ) }
72
+ hideLabelFromVision
73
+ options={ VISIBILITY_OPTIONS }
74
+ selected={ hasPassword ? 'password' : visibility }
75
+ onChange={ updateVisibility }
111
76
  />
112
77
  { hasPassword && (
113
- <div className="editor-post-visibility__password">
114
- <VisuallyHidden
115
- as="label"
116
- htmlFor={ `editor-post-visibility__password-input-${ instanceId }` }
117
- >
118
- { __( 'Create password' ) }
119
- </VisuallyHidden>
120
- <input
121
- className="editor-post-visibility__password-input"
122
- id={ `editor-post-visibility__password-input-${ instanceId }` }
123
- type="text"
124
- onChange={ updatePassword }
125
- value={ password }
126
- placeholder={ __( 'Use a secure password' ) }
127
- />
128
- </div>
78
+ <TextControl
79
+ label={ __( 'Password' ) }
80
+ onChange={ updatePassword }
81
+ value={ password }
82
+ placeholder={ __( 'Use a secure password' ) }
83
+ type="text"
84
+ id={ `editor-post-visibility__password-input-${ instanceId }` }
85
+ __next40pxDefaultSize
86
+ __nextHasNoMarginBottom
87
+ maxLength={ 255 }
88
+ />
129
89
  ) }
130
- </fieldset>
131
- <ConfirmDialog
132
- isOpen={ showPrivateConfirmDialog }
133
- onConfirm={ confirmPrivate }
134
- onCancel={ handleDialogCancel }
135
- confirmButtonText={ __( 'Publish' ) }
136
- size="medium"
137
- >
138
- { __( 'Would you like to privately publish this post now?' ) }
139
- </ConfirmDialog>
140
- </div>
141
- );
142
- }
143
-
144
- function PostVisibilityChoice( { instanceId, value, label, info, ...props } ) {
145
- return (
146
- <div className="editor-post-visibility__choice">
147
- <input
148
- type="radio"
149
- name={ `editor-post-visibility__setting-${ instanceId }` }
150
- value={ value }
151
- id={ `editor-post-${ value }-${ instanceId }` }
152
- aria-describedby={ `editor-post-${ value }-${ instanceId }-description` }
153
- className="editor-post-visibility__radio"
154
- { ...props }
155
- />
156
- <label
157
- htmlFor={ `editor-post-${ value }-${ instanceId }` }
158
- className="editor-post-visibility__label"
159
- >
160
- { label }
161
- </label>
162
- <p
163
- id={ `editor-post-${ value }-${ instanceId }-description` }
164
- className="editor-post-visibility__info"
165
- >
166
- { info }
167
- </p>
90
+ </VStack>
168
91
  </div>
169
92
  );
170
93
  }
@@ -6,7 +6,7 @@ import { useSelect } from '@wordpress/data';
6
6
  /**
7
7
  * Internal dependencies
8
8
  */
9
- import { visibilityOptions } from './utils';
9
+ import { VISIBILITY_OPTIONS } from './utils';
10
10
  import { store as editorStore } from '../../store';
11
11
 
12
12
  /**
@@ -24,8 +24,11 @@ export default function PostVisibilityLabel() {
24
24
  * @return {string} Post visibility label.
25
25
  */
26
26
  export function usePostVisibilityLabel() {
27
- const visibility = useSelect( ( select ) =>
28
- select( editorStore ).getEditedPostVisibility()
27
+ const visibility = useSelect(
28
+ ( select ) => select( editorStore ).getEditedPostVisibility(),
29
+ []
29
30
  );
30
- return visibilityOptions[ visibility ]?.label;
31
+
32
+ return VISIBILITY_OPTIONS.find( ( option ) => option.value === visibility )
33
+ ?.label;
31
34
  }
@@ -3,17 +3,20 @@
3
3
  */
4
4
  import { __ } from '@wordpress/i18n';
5
5
 
6
- export const visibilityOptions = {
7
- public: {
6
+ export const VISIBILITY_OPTIONS = [
7
+ {
8
8
  label: __( 'Public' ),
9
- info: __( 'Visible to everyone.' ),
9
+ value: 'public',
10
+ description: __( 'Visible to everyone.' ),
10
11
  },
11
- private: {
12
+ {
12
13
  label: __( 'Private' ),
13
- info: __( 'Only visible to site admins and editors.' ),
14
+ value: 'private',
15
+ description: __( 'Only visible to site admins and editors.' ),
14
16
  },
15
- password: {
17
+ {
16
18
  label: __( 'Password protected' ),
17
- info: __( 'Only those with the password can view this post.' ),
19
+ value: 'password',
20
+ description: __( 'Only visible to those who know the password.' ),
18
21
  },
19
- };
22
+ ];
@@ -182,6 +182,7 @@ export const ExperimentalEditorProvider = withRegistryProvider(
182
182
  } = unlock( select( editorStore ) );
183
183
  const { getEntitiesConfig } = select( coreStore );
184
184
 
185
+ const _mode = getRenderingMode();
185
186
  const _defaultMode = getDefaultRenderingMode( post.type );
186
187
  /**
187
188
  * To avoid content "flash", wait until rendering mode has been resolved.
@@ -190,16 +191,20 @@ export const ExperimentalEditorProvider = withRegistryProvider(
190
191
  * - Wait for template to be resolved if the default mode is 'template-locked'.
191
192
  * - Wait for default mode to be resolved otherwise.
192
193
  */
193
- const hasResolvedMode =
194
+ const hasResolvedDefaultMode =
194
195
  _defaultMode === 'template-locked'
195
196
  ? hasTemplate
196
197
  : _defaultMode !== undefined;
198
+ // Wait until the default mode is retrieved and start rendering canvas.
199
+ const isRenderingModeReady = _defaultMode !== undefined;
197
200
 
198
201
  return {
199
202
  editorSettings: getEditorSettings(),
200
- isReady: __unstableIsEditorReady() && hasResolvedMode,
201
- mode: getRenderingMode(),
202
- defaultMode: _defaultMode,
203
+ isReady: __unstableIsEditorReady(),
204
+ mode: isRenderingModeReady ? _mode : undefined,
205
+ defaultMode: hasResolvedDefaultMode
206
+ ? _defaultMode
207
+ : undefined,
203
208
  selection: getEditorSelection(),
204
209
  postTypeEntities:
205
210
  post.type === 'wp_template'
package/src/style.scss CHANGED
@@ -41,7 +41,6 @@
41
41
  @import "./components/post-text-editor/style.scss";
42
42
  @import "./components/post-title/style.scss";
43
43
  @import "./components/post-url/style.scss";
44
- @import "./components/post-visibility/style.scss";
45
44
  @import "./components/posts-per-page/style.scss";
46
45
  @import "./components/post-trash/style.scss";
47
46
  @import "./components/preview-dropdown/style.scss";