@wordpress/edit-post 6.17.0 → 6.18.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 (82) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/block-manager/category.js +1 -1
  3. package/build/components/block-manager/category.js.map +1 -1
  4. package/build/components/block-manager/index.js +1 -1
  5. package/build/components/block-manager/index.js.map +1 -1
  6. package/build/components/header/header-toolbar/index.js +0 -6
  7. package/build/components/header/header-toolbar/index.js.map +1 -1
  8. package/build/components/header/index.js +5 -4
  9. package/build/components/header/index.js.map +1 -1
  10. package/build/components/header/more-menu/index.js +1 -3
  11. package/build/components/header/more-menu/index.js.map +1 -1
  12. package/build/components/header/writing-menu/index.js +13 -14
  13. package/build/components/header/writing-menu/index.js.map +1 -1
  14. package/build/components/keyboard-shortcut-help-modal/shortcut.js +1 -7
  15. package/build/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
  16. package/build/components/keyboard-shortcuts/index.js +3 -5
  17. package/build/components/keyboard-shortcuts/index.js.map +1 -1
  18. package/build/components/layout/index.js +1 -6
  19. package/build/components/layout/index.js.map +1 -1
  20. package/build/components/secondary-sidebar/list-view-outline.js +119 -0
  21. package/build/components/secondary-sidebar/list-view-outline.js.map +1 -0
  22. package/build/components/secondary-sidebar/list-view-sidebar.js +36 -11
  23. package/build/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
  24. package/build/components/visual-editor/index.js +4 -1
  25. package/build/components/visual-editor/index.js.map +1 -1
  26. package/build/store/actions.js +23 -34
  27. package/build/store/actions.js.map +1 -1
  28. package/build/store/reducer.js +29 -8
  29. package/build/store/reducer.js.map +1 -1
  30. package/build-module/components/block-manager/category.js +2 -2
  31. package/build-module/components/block-manager/category.js.map +1 -1
  32. package/build-module/components/block-manager/index.js +2 -2
  33. package/build-module/components/block-manager/index.js.map +1 -1
  34. package/build-module/components/header/header-toolbar/index.js +1 -7
  35. package/build-module/components/header/header-toolbar/index.js.map +1 -1
  36. package/build-module/components/header/index.js +5 -4
  37. package/build-module/components/header/index.js.map +1 -1
  38. package/build-module/components/header/more-menu/index.js +1 -3
  39. package/build-module/components/header/more-menu/index.js.map +1 -1
  40. package/build-module/components/header/writing-menu/index.js +13 -14
  41. package/build-module/components/header/writing-menu/index.js.map +1 -1
  42. package/build-module/components/keyboard-shortcut-help-modal/shortcut.js +1 -6
  43. package/build-module/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
  44. package/build-module/components/keyboard-shortcuts/index.js +4 -6
  45. package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
  46. package/build-module/components/layout/index.js +1 -6
  47. package/build-module/components/layout/index.js.map +1 -1
  48. package/build-module/components/secondary-sidebar/list-view-outline.js +108 -0
  49. package/build-module/components/secondary-sidebar/list-view-outline.js.map +1 -0
  50. package/build-module/components/secondary-sidebar/list-view-sidebar.js +34 -12
  51. package/build-module/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
  52. package/build-module/components/visual-editor/index.js +3 -1
  53. package/build-module/components/visual-editor/index.js.map +1 -1
  54. package/build-module/store/actions.js +22 -32
  55. package/build-module/store/actions.js.map +1 -1
  56. package/build-module/store/reducer.js +30 -7
  57. package/build-module/store/reducer.js.map +1 -1
  58. package/build-style/style-rtl.css +60 -6
  59. package/build-style/style.css +60 -6
  60. package/package.json +27 -27
  61. package/src/components/block-manager/category.js +2 -2
  62. package/src/components/block-manager/index.js +2 -2
  63. package/src/components/header/fullscreen-mode-close/test/__snapshots__/index.js.snap +26 -0
  64. package/src/components/header/fullscreen-mode-close/test/index.js +10 -12
  65. package/src/components/header/header-toolbar/index.js +0 -8
  66. package/src/components/header/index.js +4 -1
  67. package/src/components/header/more-menu/index.js +1 -1
  68. package/src/components/header/style.scss +0 -1
  69. package/src/components/header/writing-menu/index.js +13 -11
  70. package/src/components/keyboard-shortcut-help-modal/shortcut.js +15 -18
  71. package/src/components/keyboard-shortcuts/index.js +6 -8
  72. package/src/components/layout/index.js +1 -8
  73. package/src/components/preferences-modal/test/__snapshots__/index.js.snap +48 -43
  74. package/src/components/secondary-sidebar/list-view-outline.js +98 -0
  75. package/src/components/secondary-sidebar/list-view-sidebar.js +47 -8
  76. package/src/components/secondary-sidebar/style.scss +64 -8
  77. package/src/components/sidebar/plugin-post-status-info/test/__snapshots__/index.js.snap +6 -4
  78. package/src/components/sidebar/plugin-post-status-info/test/index.js +1 -1
  79. package/src/components/visual-editor/index.js +9 -3
  80. package/src/store/actions.js +16 -21
  81. package/src/store/reducer.js +28 -8
  82. package/src/store/test/reducer.js +32 -2
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { castArray, reduce } from 'lodash';
4
+ import { reduce } from 'lodash';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
@@ -296,7 +296,10 @@ export const showBlockTypes =
296
296
  .get( 'core/edit-post', 'hiddenBlockTypes' ) ?? [];
297
297
 
298
298
  const newBlockNames = existingBlockNames.filter(
299
- ( type ) => ! castArray( blockNames ).includes( type )
299
+ ( type ) =>
300
+ ! (
301
+ Array.isArray( blockNames ) ? blockNames : [ blockNames ]
302
+ ).includes( type )
300
303
  );
301
304
 
302
305
  registry
@@ -319,7 +322,7 @@ export const hideBlockTypes =
319
322
 
320
323
  const mergedBlockNames = new Set( [
321
324
  ...existingBlockNames,
322
- ...castArray( blockNames ),
325
+ ...( Array.isArray( blockNames ) ? blockNames : [ blockNames ] ),
323
326
  ] );
324
327
 
325
328
  registry
@@ -330,18 +333,16 @@ export const hideBlockTypes =
330
333
  };
331
334
 
332
335
  /**
333
- * Returns an action object used in signaling
334
- * what Meta boxes are available in which location.
336
+ * Stores info about which Meta boxes are available in which location.
335
337
  *
336
338
  * @param {Object} metaBoxesPerLocation Meta boxes per location.
337
339
  */
338
- export const setAvailableMetaBoxesPerLocation =
339
- ( metaBoxesPerLocation ) =>
340
- ( { dispatch } ) =>
341
- dispatch( {
342
- type: 'SET_META_BOXES_PER_LOCATIONS',
343
- metaBoxesPerLocation,
344
- } );
340
+ export function setAvailableMetaBoxesPerLocation( metaBoxesPerLocation ) {
341
+ return {
342
+ type: 'SET_META_BOXES_PER_LOCATIONS',
343
+ metaBoxesPerLocation,
344
+ };
345
+ }
345
346
 
346
347
  /**
347
348
  * Update a metabox.
@@ -566,7 +567,6 @@ export const initializeMetaBoxes =
566
567
  let wasAutosavingPost = registry
567
568
  .select( editorStore )
568
569
  .isAutosavingPost();
569
- const hasMetaBoxes = select.hasMetaBoxes();
570
570
 
571
571
  // Save metaboxes when performing a full save on the post.
572
572
  registry.subscribe( async () => {
@@ -575,17 +575,12 @@ export const initializeMetaBoxes =
575
575
  .select( editorStore )
576
576
  .isAutosavingPost();
577
577
 
578
- // Save metaboxes on save completion, except for autosaves that are not a post preview.
579
- //
580
- // Meta boxes are initialized once at page load. It is not necessary to
581
- // account for updates on each state change.
582
- //
583
- // See: https://github.com/WordPress/WordPress/blob/5.1.1/wp-admin/includes/post.php#L2307-L2309.
578
+ // Save metaboxes on save completion, except for autosaves.
584
579
  const shouldTriggerMetaboxesSave =
585
- hasMetaBoxes &&
586
580
  wasSavingPost &&
581
+ ! wasAutosavingPost &&
587
582
  ! isSavingPost &&
588
- ! wasAutosavingPost;
583
+ select.hasMetaBoxes();
589
584
 
590
585
  // Save current state for next inspection.
591
586
  wasSavingPost = isSavingPost;
@@ -1,8 +1,3 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { includes } from 'lodash';
5
-
6
1
  /**
7
2
  * WordPress dependencies
8
3
  */
@@ -19,7 +14,7 @@ import { combineReducers } from '@wordpress/data';
19
14
  export function removedPanels( state = [], action ) {
20
15
  switch ( action.type ) {
21
16
  case 'REMOVE_PANEL':
22
- if ( ! includes( state, action.panelName ) ) {
17
+ if ( ! state.includes( action.panelName ) ) {
23
18
  return [ ...state, action.panelName ];
24
19
  }
25
20
  }
@@ -80,6 +75,21 @@ export function isSavingMetaBoxes( state = false, action ) {
80
75
  }
81
76
  }
82
77
 
78
+ function mergeMetaboxes( metaboxes = [], newMetaboxes ) {
79
+ const mergedMetaboxes = [ ...metaboxes ];
80
+ for ( const metabox of newMetaboxes ) {
81
+ const existing = mergedMetaboxes.findIndex(
82
+ ( box ) => box.id === metabox.id
83
+ );
84
+ if ( existing !== -1 ) {
85
+ mergedMetaboxes[ existing ] = metabox;
86
+ } else {
87
+ mergedMetaboxes.push( metabox );
88
+ }
89
+ }
90
+ return mergedMetaboxes;
91
+ }
92
+
83
93
  /**
84
94
  * Reducer keeping track of the meta boxes per location.
85
95
  *
@@ -90,8 +100,18 @@ export function isSavingMetaBoxes( state = false, action ) {
90
100
  */
91
101
  export function metaBoxLocations( state = {}, action ) {
92
102
  switch ( action.type ) {
93
- case 'SET_META_BOXES_PER_LOCATIONS':
94
- return action.metaBoxesPerLocation;
103
+ case 'SET_META_BOXES_PER_LOCATIONS': {
104
+ const newState = { ...state };
105
+ for ( const [ location, metaboxes ] of Object.entries(
106
+ action.metaBoxesPerLocation
107
+ ) ) {
108
+ newState[ location ] = mergeMetaboxes(
109
+ newState[ location ],
110
+ metaboxes
111
+ );
112
+ }
113
+ return newState;
114
+ }
95
115
  }
96
116
 
97
117
  return state;
@@ -78,14 +78,44 @@ describe( 'state', () => {
78
78
  const action = {
79
79
  type: 'SET_META_BOXES_PER_LOCATIONS',
80
80
  metaBoxesPerLocation: {
81
- normal: [ 'postcustom' ],
81
+ normal: [ { id: 'postcustom' } ],
82
82
  },
83
83
  };
84
84
 
85
85
  const state = metaBoxLocations( undefined, action );
86
86
 
87
87
  expect( state ).toEqual( {
88
- normal: [ 'postcustom' ],
88
+ normal: [ { id: 'postcustom' } ],
89
+ } );
90
+ } );
91
+
92
+ it( 'should merge new meta box locations into the existing ones', () => {
93
+ const oldState = {
94
+ normal: [
95
+ { id: 'a', title: 'A' },
96
+ { id: 'b', title: 'B' },
97
+ ],
98
+ side: [ { id: 's', title: 'S' } ],
99
+ };
100
+ const action = {
101
+ type: 'SET_META_BOXES_PER_LOCATIONS',
102
+ metaBoxesPerLocation: {
103
+ normal: [
104
+ { id: 'b', title: 'B-updated' },
105
+ { id: 'c', title: 'C' },
106
+ ],
107
+ advanced: [ { id: 'd', title: 'D' } ],
108
+ },
109
+ };
110
+ const newState = metaBoxLocations( oldState, action );
111
+ expect( newState ).toEqual( {
112
+ normal: [
113
+ { id: 'a', title: 'A' },
114
+ { id: 'b', title: 'B-updated' },
115
+ { id: 'c', title: 'C' },
116
+ ],
117
+ advanced: [ { id: 'd', title: 'D' } ],
118
+ side: [ { id: 's', title: 'S' } ],
89
119
  } );
90
120
  } );
91
121
  } );