@wordpress/editor 14.0.3 → 14.0.5

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 (66) hide show
  1. package/build/bindings/pattern-overrides.js +8 -5
  2. package/build/bindings/pattern-overrides.js.map +1 -1
  3. package/build/bindings/post-meta.js +4 -0
  4. package/build/bindings/post-meta.js.map +1 -1
  5. package/build/components/editor/index.js +5 -0
  6. package/build/components/editor/index.js.map +1 -1
  7. package/build/components/editor-interface/index.js +2 -1
  8. package/build/components/editor-interface/index.js.map +1 -1
  9. package/build/components/page-attributes/parent.js +2 -1
  10. package/build/components/page-attributes/parent.js.map +1 -1
  11. package/build/components/post-actions/actions.js +14 -36
  12. package/build/components/post-actions/actions.js.map +1 -1
  13. package/build/components/post-actions/export-pattern-action.js +2 -2
  14. package/build/components/post-actions/export-pattern-action.js.map +1 -1
  15. package/build/components/post-saved-state/index.js +11 -1
  16. package/build/components/post-saved-state/index.js.map +1 -1
  17. package/build/components/post-status/index.js +2 -1
  18. package/build/components/post-status/index.js.map +1 -1
  19. package/build/components/save-publish-panels/index.js +30 -16
  20. package/build/components/save-publish-panels/index.js.map +1 -1
  21. package/build/hooks/pattern-overrides.js +2 -2
  22. package/build/hooks/pattern-overrides.js.map +1 -1
  23. package/build/store/utils/is-template-revertable.js +6 -8
  24. package/build/store/utils/is-template-revertable.js.map +1 -1
  25. package/build-module/bindings/pattern-overrides.js +8 -5
  26. package/build-module/bindings/pattern-overrides.js.map +1 -1
  27. package/build-module/bindings/post-meta.js +4 -0
  28. package/build-module/bindings/post-meta.js.map +1 -1
  29. package/build-module/components/editor/index.js +5 -0
  30. package/build-module/components/editor/index.js.map +1 -1
  31. package/build-module/components/editor-interface/index.js +2 -1
  32. package/build-module/components/editor-interface/index.js.map +1 -1
  33. package/build-module/components/page-attributes/parent.js +2 -1
  34. package/build-module/components/page-attributes/parent.js.map +1 -1
  35. package/build-module/components/post-actions/actions.js +14 -36
  36. package/build-module/components/post-actions/actions.js.map +1 -1
  37. package/build-module/components/post-actions/export-pattern-action.js +2 -2
  38. package/build-module/components/post-actions/export-pattern-action.js.map +1 -1
  39. package/build-module/components/post-saved-state/index.js +11 -1
  40. package/build-module/components/post-saved-state/index.js.map +1 -1
  41. package/build-module/components/post-status/index.js +1 -1
  42. package/build-module/components/post-status/index.js.map +1 -1
  43. package/build-module/components/save-publish-panels/index.js +30 -16
  44. package/build-module/components/save-publish-panels/index.js.map +1 -1
  45. package/build-module/hooks/pattern-overrides.js +3 -1
  46. package/build-module/hooks/pattern-overrides.js.map +1 -1
  47. package/build-module/store/utils/is-template-revertable.js +6 -8
  48. package/build-module/store/utils/is-template-revertable.js.map +1 -1
  49. package/build-style/style-rtl.css +13 -1
  50. package/build-style/style.css +13 -1
  51. package/package.json +6 -6
  52. package/src/bindings/pattern-overrides.js +9 -10
  53. package/src/bindings/post-meta.js +5 -0
  54. package/src/components/editor/index.js +6 -0
  55. package/src/components/editor-interface/index.js +17 -12
  56. package/src/components/page-attributes/parent.js +6 -3
  57. package/src/components/post-actions/actions.js +33 -58
  58. package/src/components/post-actions/export-pattern-action.js +4 -2
  59. package/src/components/post-featured-image/style.scss +15 -0
  60. package/src/components/post-panel-row/style.scss +1 -0
  61. package/src/components/post-saved-state/index.js +11 -1
  62. package/src/components/post-status/index.js +1 -1
  63. package/src/components/save-publish-panels/index.js +33 -23
  64. package/src/components/visual-editor/style.scss +1 -1
  65. package/src/hooks/pattern-overrides.js +4 -1
  66. package/src/store/utils/is-template-revertable.js +8 -8
@@ -59,11 +59,6 @@ function isTemplateRemovable( template ) {
59
59
  ! template.templatePart?.has_theme_file
60
60
  );
61
61
  }
62
- const canDeleteOrReset = ( item ) => {
63
- const isTemplatePart = item.type === TEMPLATE_PART_POST_TYPE;
64
- const isUserPattern = item.type === PATTERN_TYPES.user;
65
- return isUserPattern || ( isTemplatePart && item.isCustom );
66
- };
67
62
 
68
63
  function getItemTitle( item ) {
69
64
  if ( typeof item.title === 'string' ) {
@@ -254,16 +249,14 @@ const trashPostAction = {
254
249
  __( '"%s" moved to trash.' ),
255
250
  getItemTitle( items[ 0 ] )
256
251
  );
257
- } else if ( items[ 0 ].type === 'page' ) {
258
- successMessage = sprintf(
259
- /* translators: The number of items. */
260
- __( '%s items moved to trash.' ),
261
- items.length
262
- );
263
252
  } else {
264
253
  successMessage = sprintf(
265
- /* translators: The number of posts. */
266
- __( '%s items move to trash.' ),
254
+ /* translators: The number of items. */
255
+ _n(
256
+ '%s item moved to trash.',
257
+ '%s items moved to trash.',
258
+ items.length
259
+ ),
267
260
  items.length
268
261
  );
269
262
  }
@@ -881,21 +874,11 @@ const duplicatePostAction = {
881
874
  },
882
875
  };
883
876
 
884
- const isTemplatePartRevertable = ( item ) => {
885
- if ( ! item ) {
886
- return false;
887
- }
888
- const hasThemeFile = item.templatePart?.has_theme_file;
889
- return canDeleteOrReset( item ) && hasThemeFile;
890
- };
891
-
892
877
  const resetTemplateAction = {
893
878
  id: 'reset-template',
894
879
  label: __( 'Reset' ),
895
880
  isEligible: ( item ) => {
896
- return item.type === TEMPLATE_PART_POST_TYPE
897
- ? isTemplatePartRevertable( item )
898
- : isTemplateRevertable( item );
881
+ return isTemplateRevertable( item );
899
882
  },
900
883
  icon: backup,
901
884
  supportsBulk: true,
@@ -907,47 +890,39 @@ const resetTemplateAction = {
907
890
  onActionPerformed,
908
891
  } ) => {
909
892
  const [ isBusy, setIsBusy ] = useState( false );
910
- const { revertTemplate, removeTemplates } = unlock(
911
- useDispatch( editorStore )
912
- );
893
+ const { revertTemplate } = unlock( useDispatch( editorStore ) );
913
894
  const { saveEditedEntityRecord } = useDispatch( coreStore );
914
895
  const { createSuccessNotice, createErrorNotice } =
915
896
  useDispatch( noticesStore );
916
897
  const onConfirm = async () => {
917
898
  try {
918
- if ( items[ 0 ].type === TEMPLATE_PART_POST_TYPE ) {
919
- await removeTemplates( items );
920
- } else {
921
- for ( const template of items ) {
922
- if ( template.type === TEMPLATE_POST_TYPE ) {
923
- await revertTemplate( template, {
924
- allowUndo: false,
925
- } );
926
- await saveEditedEntityRecord(
927
- 'postType',
928
- template.type,
929
- template.id
930
- );
931
- }
932
- }
933
- createSuccessNotice(
934
- items.length > 1
935
- ? sprintf(
936
- /* translators: The number of items. */
937
- __( '%s items reset.' ),
938
- items.length
939
- )
940
- : sprintf(
941
- /* translators: The template/part's name. */
942
- __( '"%s" reset.' ),
943
- decodeEntities( getItemTitle( items[ 0 ] ) )
944
- ),
945
- {
946
- type: 'snackbar',
947
- id: 'revert-template-action',
948
- }
899
+ for ( const template of items ) {
900
+ await revertTemplate( template, {
901
+ allowUndo: false,
902
+ } );
903
+ await saveEditedEntityRecord(
904
+ 'postType',
905
+ template.type,
906
+ template.id
949
907
  );
950
908
  }
909
+ createSuccessNotice(
910
+ items.length > 1
911
+ ? sprintf(
912
+ /* translators: The number of items. */
913
+ __( '%s items reset.' ),
914
+ items.length
915
+ )
916
+ : sprintf(
917
+ /* translators: The template/part's name. */
918
+ __( '"%s" reset.' ),
919
+ decodeEntities( getItemTitle( items[ 0 ] ) )
920
+ ),
921
+ {
922
+ type: 'snackbar',
923
+ id: 'revert-template-action',
924
+ }
925
+ );
951
926
  } catch ( error ) {
952
927
  let fallbackErrorMessage;
953
928
  if ( items[ 0 ].type === TEMPLATE_POST_TYPE ) {
@@ -24,8 +24,10 @@ function getJsonFromItem( item ) {
24
24
  {
25
25
  __file: item.type,
26
26
  title: item.title || item.name,
27
- content: item.patternPost.content.raw,
28
- syncStatus: item.patternPost.wp_pattern_sync_status,
27
+ content: item?.patternPost?.content?.raw || item.content,
28
+ syncStatus:
29
+ item?.patternPost?.wp_pattern_sync_status ||
30
+ item.wp_pattern_sync_status,
29
31
  },
30
32
  null,
31
33
  2
@@ -20,6 +20,21 @@
20
20
  opacity: 1;
21
21
  }
22
22
  }
23
+
24
+ .components-drop-zone__content {
25
+ border-radius: $radius-block-ui;
26
+ }
27
+
28
+ // Align text and icons horizontally to avoid clipping when the featured image is not set.
29
+ &:has(.editor-post-featured-image__toggle) .components-drop-zone .components-drop-zone__content-inner {
30
+ display: flex;
31
+ align-items: center;
32
+ gap: $grid-unit-10;
33
+
34
+ .components-drop-zone__content-icon {
35
+ margin: 0;
36
+ }
37
+ }
23
38
  }
24
39
 
25
40
  .editor-post-featured-image__toggle,
@@ -25,6 +25,7 @@
25
25
  .components-button {
26
26
  max-width: 100%;
27
27
  text-align: left;
28
+ white-space: normal;
28
29
  text-wrap: balance; // Fallback for Safari.
29
30
  text-wrap: pretty;
30
31
  height: auto;
@@ -21,6 +21,7 @@ import { store as preferencesStore } from '@wordpress/preferences';
21
21
  /**
22
22
  * Internal dependencies
23
23
  */
24
+ import { STATUS_OPTIONS } from '../../components/post-status';
24
25
  import { store as editorStore } from '../../store';
25
26
 
26
27
  /**
@@ -104,10 +105,19 @@ export default function PostSavedState( { forceIsDirty } ) {
104
105
  return null;
105
106
  }
106
107
 
108
+ // We shouldn't render the button if the post has not one of the following statuses: pending, draft, auto-draft.
109
+ // The reason for this is that this button handles the `save as pending` and `save draft` actions.
110
+ // An exception for this is when the post has a custom status and there should be a way to save changes without
111
+ // having to publish. This should be handled better in the future when custom statuses have better support.
112
+ // @see https://github.com/WordPress/gutenberg/issues/3144.
113
+ const isIneligibleStatus =
114
+ ! [ 'pending', 'draft', 'auto-draft' ].includes( postStatus ) &&
115
+ STATUS_OPTIONS.map( ( { value } ) => value ).includes( postStatus );
116
+
107
117
  if (
108
118
  isPublished ||
109
119
  isScheduled ||
110
- ! [ 'pending', 'draft', 'auto-draft' ].includes( postStatus ) ||
120
+ isIneligibleStatus ||
111
121
  ( postStatusHasChanged &&
112
122
  [ 'pending', 'draft' ].includes( postStatus ) )
113
123
  ) {
@@ -39,7 +39,7 @@ const labels = {
39
39
  publish: __( 'Published' ),
40
40
  };
41
41
 
42
- const STATUS_OPTIONS = [
42
+ export const STATUS_OPTIONS = [
43
43
  {
44
44
  label: (
45
45
  <>
@@ -30,20 +30,28 @@ export default function SavePublishPanels( {
30
30
  useDispatch( editorStore );
31
31
  const {
32
32
  publishSidebarOpened,
33
- hasNonPostEntityChanges,
34
- hasPostMetaChanges,
35
- } = useSelect(
36
- ( select ) => ( {
37
- publishSidebarOpened:
38
- select( editorStore ).isPublishSidebarOpened(),
39
- hasNonPostEntityChanges:
40
- select( editorStore ).hasNonPostEntityChanges(),
41
- hasPostMetaChanges: unlock(
42
- select( editorStore )
43
- ).hasPostMetaChanges(),
44
- } ),
45
- []
46
- );
33
+ isPublishable,
34
+ isDirty,
35
+ hasOtherEntitiesChanges,
36
+ } = useSelect( ( select ) => {
37
+ const {
38
+ isPublishSidebarOpened,
39
+ isEditedPostPublishable,
40
+ isCurrentPostPublished,
41
+ isEditedPostDirty,
42
+ hasNonPostEntityChanges,
43
+ } = select( editorStore );
44
+ const _hasOtherEntitiesChanges =
45
+ hasNonPostEntityChanges() ||
46
+ unlock( select( editorStore ) ).hasPostMetaChanges();
47
+ return {
48
+ publishSidebarOpened: isPublishSidebarOpened(),
49
+ isPublishable:
50
+ ! isCurrentPostPublished() && isEditedPostPublishable(),
51
+ isDirty: _hasOtherEntitiesChanges || isEditedPostDirty(),
52
+ hasOtherEntitiesChanges: _hasOtherEntitiesChanges,
53
+ };
54
+ }, [] );
47
55
 
48
56
  const openEntitiesSavedStates = useCallback(
49
57
  () => setEntitiesSavedStatesCallback( true ),
@@ -62,29 +70,31 @@ export default function SavePublishPanels( {
62
70
  PostPublishExtension={ PluginPostPublishPanel.Slot }
63
71
  />
64
72
  );
65
- } else if ( hasNonPostEntityChanges || hasPostMetaChanges ) {
73
+ } else if ( isPublishable && ! hasOtherEntitiesChanges ) {
66
74
  unmountableContent = (
67
- <div className="editor-layout__toggle-entities-saved-states-panel">
75
+ <div className="editor-layout__toggle-publish-panel">
68
76
  <Button
69
77
  variant="secondary"
70
- className="editor-layout__toggle-entities-saved-states-panel-button"
71
- onClick={ openEntitiesSavedStates }
78
+ className="editor-layout__toggle-publish-panel-button"
79
+ onClick={ togglePublishSidebar }
72
80
  aria-expanded={ false }
73
81
  >
74
- { __( 'Open save panel' ) }
82
+ { __( 'Open publish panel' ) }
75
83
  </Button>
76
84
  </div>
77
85
  );
78
86
  } else {
79
87
  unmountableContent = (
80
- <div className="editor-layout__toggle-publish-panel">
88
+ <div className="editor-layout__toggle-entities-saved-states-panel">
81
89
  <Button
82
90
  variant="secondary"
83
- className="editor-layout__toggle-publish-panel-button"
84
- onClick={ togglePublishSidebar }
91
+ className="editor-layout__toggle-entities-saved-states-panel-button"
92
+ onClick={ openEntitiesSavedStates }
85
93
  aria-expanded={ false }
94
+ disabled={ ! isDirty }
95
+ __experimentalIsFocusable
86
96
  >
87
- { __( 'Open publish panel' ) }
97
+ { __( 'Open save panel' ) }
88
98
  </Button>
89
99
  </div>
90
100
  );
@@ -19,7 +19,7 @@
19
19
 
20
20
  // In the iframed canvas this keeps extra scrollbars from appearing (when block toolbars overflow). In the
21
21
  // legacy (non-iframed) canvas, overflow must not be hidden in order to maintain support for sticky positioning.
22
- .is-iframed {
22
+ &.is-iframed {
23
23
  overflow: hidden;
24
24
  }
25
25
 
@@ -14,6 +14,8 @@ import { store as blocksStore } from '@wordpress/blocks';
14
14
  import { store as editorStore } from '../store';
15
15
  import { unlock } from '../lock-unlock';
16
16
 
17
+ /** @typedef {import('@wordpress/blocks').WPBlockSettings} WPBlockSettings */
18
+
17
19
  const {
18
20
  PatternOverridesControls,
19
21
  ResetOverridesControl,
@@ -46,7 +48,8 @@ const withPatternOverrideControls = createHigherOrderComponent(
46
48
  { isSupportedBlock && <PatternOverridesBlockControls /> }
47
49
  </>
48
50
  );
49
- }
51
+ },
52
+ 'withPatternOverrideControls'
50
53
  );
51
54
 
52
55
  // Split into a separate component to avoid a store subscription
@@ -6,18 +6,18 @@ import { TEMPLATE_ORIGINS } from '../constants';
6
6
  // Copy of the function from packages/edit-site/src/utils/is-template-revertable.js
7
7
 
8
8
  /**
9
- * Check if a template is revertable to its original theme-provided template file.
9
+ * Check if a template or template part is revertable to its original theme-provided file.
10
10
  *
11
- * @param {Object} template The template entity to check.
12
- * @return {boolean} Whether the template is revertable.
11
+ * @param {Object} templateOrTemplatePart The entity to check.
12
+ * @return {boolean} Whether the entity is revertable.
13
13
  */
14
- export default function isTemplateRevertable( template ) {
15
- if ( ! template ) {
14
+ export default function isTemplateRevertable( templateOrTemplatePart ) {
15
+ if ( ! templateOrTemplatePart ) {
16
16
  return false;
17
17
  }
18
- /* eslint-disable camelcase */
18
+
19
19
  return (
20
- template?.source === TEMPLATE_ORIGINS.custom && template?.has_theme_file
20
+ templateOrTemplatePart.source === TEMPLATE_ORIGINS.custom &&
21
+ templateOrTemplatePart.has_theme_file
21
22
  );
22
- /* eslint-enable camelcase */
23
23
  }