@wordpress/editor 11.0.2 → 12.0.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 (95) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +1 -1
  3. package/build/components/character-count/index.js +1 -1
  4. package/build/components/character-count/index.js.map +1 -1
  5. package/build/components/editor-help/help-get-support-button.native.js +46 -0
  6. package/build/components/editor-help/help-get-support-button.native.js.map +1 -0
  7. package/build/components/editor-help/index.native.js +20 -2
  8. package/build/components/editor-help/index.native.js.map +1 -1
  9. package/build/components/global-keyboard-shortcuts/save-shortcut.js +12 -14
  10. package/build/components/global-keyboard-shortcuts/save-shortcut.js.map +1 -1
  11. package/build/components/global-keyboard-shortcuts/visual-editor-shortcuts.js +0 -4
  12. package/build/components/global-keyboard-shortcuts/visual-editor-shortcuts.js.map +1 -1
  13. package/build/components/post-format/index.js +3 -1
  14. package/build/components/post-format/index.js.map +1 -1
  15. package/build/components/post-locked-modal/index.js +1 -1
  16. package/build/components/post-locked-modal/index.js.map +1 -1
  17. package/build/components/post-saved-state/index.js +37 -46
  18. package/build/components/post-saved-state/index.js.map +1 -1
  19. package/build/components/post-title/index.js +1 -1
  20. package/build/components/post-title/index.js.map +1 -1
  21. package/build/components/provider/index.native.js +3 -1
  22. package/build/components/provider/index.native.js.map +1 -1
  23. package/build/components/provider/use-block-editor-settings.js +31 -4
  24. package/build/components/provider/use-block-editor-settings.js.map +1 -1
  25. package/build/components/word-count/index.js +1 -1
  26. package/build/components/word-count/index.js.map +1 -1
  27. package/build/store/actions.js +0 -25
  28. package/build/store/actions.js.map +1 -1
  29. package/build/store/selectors.js +3 -84
  30. package/build/store/selectors.js.map +1 -1
  31. package/build/{store/utils → utils}/get-template-part-icon.js +0 -0
  32. package/build/utils/get-template-part-icon.js.map +1 -0
  33. package/build/utils/index.js +8 -0
  34. package/build/utils/index.js.map +1 -1
  35. package/build-module/components/character-count/index.js +1 -1
  36. package/build-module/components/character-count/index.js.map +1 -1
  37. package/build-module/components/editor-help/help-get-support-button.native.js +34 -0
  38. package/build-module/components/editor-help/help-get-support-button.native.js.map +1 -0
  39. package/build-module/components/editor-help/index.native.js +18 -3
  40. package/build-module/components/editor-help/index.native.js.map +1 -1
  41. package/build-module/components/global-keyboard-shortcuts/save-shortcut.js +12 -14
  42. package/build-module/components/global-keyboard-shortcuts/save-shortcut.js.map +1 -1
  43. package/build-module/components/global-keyboard-shortcuts/visual-editor-shortcuts.js +0 -4
  44. package/build-module/components/global-keyboard-shortcuts/visual-editor-shortcuts.js.map +1 -1
  45. package/build-module/components/post-format/index.js +4 -2
  46. package/build-module/components/post-format/index.js.map +1 -1
  47. package/build-module/components/post-locked-modal/index.js +1 -1
  48. package/build-module/components/post-locked-modal/index.js.map +1 -1
  49. package/build-module/components/post-saved-state/index.js +38 -46
  50. package/build-module/components/post-saved-state/index.js.map +1 -1
  51. package/build-module/components/post-title/index.js +1 -1
  52. package/build-module/components/post-title/index.js.map +1 -1
  53. package/build-module/components/provider/index.native.js +3 -1
  54. package/build-module/components/provider/index.native.js.map +1 -1
  55. package/build-module/components/provider/use-block-editor-settings.js +30 -4
  56. package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
  57. package/build-module/components/word-count/index.js +1 -1
  58. package/build-module/components/word-count/index.js.map +1 -1
  59. package/build-module/store/actions.js +0 -23
  60. package/build-module/store/actions.js.map +1 -1
  61. package/build-module/store/selectors.js +3 -80
  62. package/build-module/store/selectors.js.map +1 -1
  63. package/build-module/{store/utils → utils}/get-template-part-icon.js +0 -0
  64. package/build-module/utils/get-template-part-icon.js.map +1 -0
  65. package/build-module/utils/index.js +1 -0
  66. package/build-module/utils/index.js.map +1 -1
  67. package/build-style/style-rtl.css +6 -1
  68. package/build-style/style.css +6 -1
  69. package/package.json +28 -28
  70. package/src/components/character-count/index.js +3 -2
  71. package/src/components/editor-help/help-get-support-button.native.js +38 -0
  72. package/src/components/editor-help/index.native.js +41 -1
  73. package/src/components/editor-help/style.android.scss +6 -0
  74. package/src/components/editor-help/style.ios.scss +6 -0
  75. package/src/components/editor-help/style.scss +21 -0
  76. package/src/components/editor-help/test/index.native.js +80 -0
  77. package/src/components/global-keyboard-shortcuts/save-shortcut.js +34 -42
  78. package/src/components/global-keyboard-shortcuts/visual-editor-shortcuts.js +8 -16
  79. package/src/components/post-format/index.js +6 -2
  80. package/src/components/post-format/style.scss +1 -0
  81. package/src/components/post-locked-modal/index.js +1 -1
  82. package/src/components/post-saved-state/index.js +41 -55
  83. package/src/components/post-saved-state/style.scss +8 -1
  84. package/src/components/post-saved-state/test/__snapshots__/index.js.snap +20 -0
  85. package/src/components/post-saved-state/test/index.js +2 -2
  86. package/src/components/post-title/index.js +1 -1
  87. package/src/components/provider/index.native.js +2 -0
  88. package/src/components/provider/use-block-editor-settings.js +24 -0
  89. package/src/components/word-count/index.js +3 -2
  90. package/src/store/actions.js +0 -28
  91. package/src/store/selectors.js +2 -105
  92. package/src/{store/utils → utils}/get-template-part-icon.js +0 -0
  93. package/src/utils/index.js +1 -0
  94. package/build/store/utils/get-template-part-icon.js.map +0 -1
  95. package/build-module/store/utils/get-template-part-icon.js.map +0 -1
@@ -48,7 +48,7 @@ describe( 'PostSavedState', () => {
48
48
  expect( wrapper.text() ).toContain( 'Saving' );
49
49
  } );
50
50
 
51
- it( 'returns null if the post is not saveable', () => {
51
+ it( 'returns a disabled button if the post is not saveable', () => {
52
52
  useSelect.mockImplementation( () => ( {
53
53
  isDirty: false,
54
54
  isNew: true,
@@ -58,7 +58,7 @@ describe( 'PostSavedState', () => {
58
58
 
59
59
  const wrapper = shallow( <PostSavedState /> );
60
60
 
61
- expect( wrapper.type() ).toBeNull();
61
+ expect( wrapper ).toMatchSnapshot();
62
62
  } );
63
63
 
64
64
  it( 'returns a switch to draft link if the post is published', () => {
@@ -61,7 +61,7 @@ export default function PostTitle() {
61
61
  isFocusMode: focusMode,
62
62
  hasFixedToolbar: _hasFixedToolbar,
63
63
  };
64
- } );
64
+ }, [] );
65
65
 
66
66
  useEffect( () => {
67
67
  if ( ! ref.current ) {
@@ -92,6 +92,7 @@ class NativeEditorProvider extends Component {
92
92
  componentDidMount() {
93
93
  const {
94
94
  capabilities,
95
+ locale,
95
96
  updateSettings,
96
97
  galleryWithImageBlocks,
97
98
  } = this.props;
@@ -100,6 +101,7 @@ class NativeEditorProvider extends Component {
100
101
  ...capabilities,
101
102
  ...{ __unstableGalleryWithImageBlocks: galleryWithImageBlocks },
102
103
  ...this.getThemeColors( this.props ),
104
+ locale,
103
105
  } );
104
106
 
105
107
  this.subscriptionParentGetHtml = subscribeParentGetHtml( () => {
@@ -13,6 +13,7 @@ import {
13
13
  __experimentalFetchLinkSuggestions as fetchLinkSuggestions,
14
14
  __experimentalFetchUrlData as fetchUrlData,
15
15
  } from '@wordpress/core-data';
16
+ import { __ } from '@wordpress/i18n';
16
17
 
17
18
  /**
18
19
  * Internal dependencies
@@ -33,6 +34,7 @@ function useBlockEditorSettings( settings, hasTemplate ) {
33
34
  reusableBlocks,
34
35
  hasUploadPermissions,
35
36
  canUseUnfilteredHTML,
37
+ userCanCreatePages,
36
38
  } = useSelect( ( select ) => {
37
39
  const { canUserUseUnfilteredHTML } = select( editorStore );
38
40
  const isWeb = Platform.OS === 'web';
@@ -61,11 +63,30 @@ function useBlockEditorSettings( settings, hasTemplate ) {
61
63
  ),
62
64
  hasResolvedLocalSiteData: hasFinishedResolvingSiteData,
63
65
  baseUrl: siteData?.url || '',
66
+ userCanCreatePages: canUser( 'create', 'pages' ),
64
67
  };
65
68
  }, [] );
66
69
 
67
70
  const { undo } = useDispatch( editorStore );
68
71
 
72
+ const { saveEntityRecord } = useDispatch( coreStore );
73
+
74
+ /**
75
+ * Creates a Post entity.
76
+ * This is utilised by the Link UI to allow for on-the-fly creation of Posts/Pages.
77
+ *
78
+ * @param {Object} options parameters for the post being created. These mirror those used on 3rd param of saveEntityRecord.
79
+ * @return {Object} the post type object that was created.
80
+ */
81
+ const createPageEntity = ( options ) => {
82
+ if ( ! userCanCreatePages ) {
83
+ return Promise.reject( {
84
+ message: __( 'You do not have permission to create Pages.' ),
85
+ } );
86
+ }
87
+ return saveEntityRecord( 'postType', 'page', options );
88
+ };
89
+
69
90
  return useMemo(
70
91
  () => ( {
71
92
  ...pick( settings, [
@@ -117,6 +138,8 @@ function useBlockEditorSettings( settings, hasTemplate ) {
117
138
  __experimentalCanUserUseUnfilteredHTML: canUseUnfilteredHTML,
118
139
  __experimentalUndo: undo,
119
140
  outlineMode: hasTemplate,
141
+ __experimentalCreatePageEntity: createPageEntity,
142
+ __experimentalUserCanCreatePages: userCanCreatePages,
120
143
  } ),
121
144
  [
122
145
  settings,
@@ -125,6 +148,7 @@ function useBlockEditorSettings( settings, hasTemplate ) {
125
148
  canUseUnfilteredHTML,
126
149
  undo,
127
150
  hasTemplate,
151
+ userCanCreatePages,
128
152
  ]
129
153
  );
130
154
  }
@@ -11,8 +11,9 @@ import { count as wordCount } from '@wordpress/wordcount';
11
11
  import { store as editorStore } from '../../store';
12
12
 
13
13
  export default function WordCount() {
14
- const content = useSelect( ( select ) =>
15
- select( editorStore ).getEditedPostAttribute( 'content' )
14
+ const content = useSelect(
15
+ ( select ) => select( editorStore ).getEditedPostAttribute( 'content' ),
16
+ []
16
17
  );
17
18
 
18
19
  /*
@@ -100,34 +100,6 @@ export function resetPost( post ) {
100
100
  };
101
101
  }
102
102
 
103
- /**
104
- * Returns an action object used in signalling that the latest autosave of the
105
- * post has been received, by initialization or autosave.
106
- *
107
- * @deprecated since 5.6. Callers should use the `receiveAutosaves( postId, autosave )`
108
- * selector from the '@wordpress/core-data' package.
109
- *
110
- * @param {Object} newAutosave Autosave post object.
111
- *
112
- * @return {Object} Action object.
113
- */
114
- export function* resetAutosave( newAutosave ) {
115
- deprecated( 'resetAutosave action (`core/editor` store)', {
116
- since: '5.3',
117
- alternative: 'receiveAutosaves action (`core` store)',
118
- } );
119
-
120
- const postId = yield controls.select( STORE_NAME, 'getCurrentPostId' );
121
- yield controls.dispatch(
122
- coreStore,
123
- 'receiveAutosaves',
124
- postId,
125
- newAutosave
126
- );
127
-
128
- return { type: '__INERT__' };
129
- }
130
-
131
103
  /**
132
104
  * Action for dispatching that a post update request has started.
133
105
  *
@@ -1,16 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import {
5
- find,
6
- get,
7
- has,
8
- isString,
9
- pick,
10
- mapValues,
11
- includes,
12
- some,
13
- } from 'lodash';
4
+ import { find, get, has, isString, includes, some } from 'lodash';
14
5
  import createSelector from 'rememo';
15
6
 
16
7
  /**
@@ -19,7 +10,6 @@ import createSelector from 'rememo';
19
10
  import {
20
11
  getFreeformContentHandlerName,
21
12
  getDefaultBlockName,
22
- isUnmodifiedDefaultBlock,
23
13
  __unstableSerializeAndClean,
24
14
  } from '@wordpress/blocks';
25
15
  import { isInTheFuture, getDate } from '@wordpress/date';
@@ -43,7 +33,7 @@ import {
43
33
  } from './constants';
44
34
  import { getPostRawValue } from './reducer';
45
35
  import { cleanForSlug } from '../utils/url';
46
- import { getTemplatePartIcon } from './utils/get-template-part-icon';
36
+ import { getTemplatePartIcon } from '../utils/get-template-part-icon';
47
37
 
48
38
  /**
49
39
  * Shared reference to an empty object for cases where it is important to avoid
@@ -678,63 +668,6 @@ export const isEditedPostAutosaveable = createRegistrySelector(
678
668
  }
679
669
  );
680
670
 
681
- /**
682
- * Returns the current autosave, or null if one is not set (i.e. if the post
683
- * has yet to be autosaved, or has been saved or published since the last
684
- * autosave).
685
- *
686
- * @deprecated since 5.6. Callers should use the `getAutosave( postType, postId, userId )`
687
- * selector from the '@wordpress/core-data' package.
688
- *
689
- * @param {Object} state Editor state.
690
- *
691
- * @return {?Object} Current autosave, if exists.
692
- */
693
- export const getAutosave = createRegistrySelector( ( select ) => ( state ) => {
694
- deprecated( "`wp.data.select( 'core/editor' ).getAutosave()`", {
695
- since: '5.3',
696
- alternative:
697
- "`wp.data.select( 'core' ).getAutosave( postType, postId, userId )`",
698
- } );
699
-
700
- const postType = getCurrentPostType( state );
701
- const postId = getCurrentPostId( state );
702
- const currentUserId = get( select( coreStore ).getCurrentUser(), [ 'id' ] );
703
- const autosave = select( coreStore ).getAutosave(
704
- postType,
705
- postId,
706
- currentUserId
707
- );
708
- return mapValues( pick( autosave, AUTOSAVE_PROPERTIES ), getPostRawValue );
709
- } );
710
-
711
- /**
712
- * Returns the true if there is an existing autosave, otherwise false.
713
- *
714
- * @deprecated since 5.6. Callers should use the `getAutosave( postType, postId, userId )` selector
715
- * from the '@wordpress/core-data' package and check for a truthy value.
716
- *
717
- * @param {Object} state Global application state.
718
- *
719
- * @return {boolean} Whether there is an existing autosave.
720
- */
721
- export const hasAutosave = createRegistrySelector( ( select ) => ( state ) => {
722
- deprecated( "`wp.data.select( 'core/editor' ).hasAutosave()`", {
723
- since: '5.3',
724
- alternative:
725
- "`!! wp.data.select( 'core' ).getAutosave( postType, postId, userId )`",
726
- } );
727
-
728
- const postType = getCurrentPostType( state );
729
- const postId = getCurrentPostId( state );
730
- const currentUserId = get( select( coreStore ).getCurrentUser(), [ 'id' ] );
731
- return !! select( coreStore ).getAutosave(
732
- postType,
733
- postId,
734
- currentUserId
735
- );
736
- } );
737
-
738
671
  /**
739
672
  * Return true if the post being edited is being scheduled. Preferring the
740
673
  * unsaved status values.
@@ -975,42 +908,6 @@ export function getSuggestedPostFormat( state ) {
975
908
  }
976
909
  }
977
910
 
978
- /**
979
- * Returns a set of blocks which are to be used in consideration of the post's
980
- * generated save content.
981
- *
982
- * @deprecated since Gutenberg 6.2.0.
983
- *
984
- * @param {Object} state Editor state.
985
- *
986
- * @return {WPBlock[]} Filtered set of blocks for save.
987
- */
988
- export function getBlocksForSerialization( state ) {
989
- deprecated( '`core/editor` getBlocksForSerialization selector', {
990
- since: '5.3',
991
- alternative: 'getEditorBlocks',
992
- hint: 'Blocks serialization pre-processing occurs at save time',
993
- } );
994
-
995
- const blocks = state.editor.present.blocks.value;
996
-
997
- // WARNING: Any changes to the logic of this function should be verified
998
- // against the implementation of isEditedPostEmpty, which bypasses this
999
- // function for performance' sake, in an assumption of this current logic
1000
- // being irrelevant to the optimized condition of emptiness.
1001
-
1002
- // A single unmodified default block is assumed to be equivalent to an
1003
- // empty post.
1004
- const isSingleUnmodifiedDefaultBlock =
1005
- blocks.length === 1 && isUnmodifiedDefaultBlock( blocks[ 0 ] );
1006
-
1007
- if ( isSingleUnmodifiedDefaultBlock ) {
1008
- return [];
1009
- }
1010
-
1011
- return blocks;
1012
- }
1013
-
1014
911
  /**
1015
912
  * Returns the content of the post being edited.
1016
913
  *
@@ -5,3 +5,4 @@ import mediaUpload from './media-upload';
5
5
 
6
6
  export { mediaUpload };
7
7
  export { cleanForSlug } from './url.js';
8
+ export { getTemplatePartIcon } from './get-template-part-icon';
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/editor/src/store/utils/get-template-part-icon.js"],"names":["getTemplatePartIcon","iconName","headerIcon","footerIcon","sidebarIcon","layoutIcon"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,mBAAT,CAA8BC,QAA9B,EAAyC;AAC/C,MAAK,aAAaA,QAAlB,EAA6B;AAC5B,WAAOC,aAAP;AACA,GAFD,MAEO,IAAK,aAAaD,QAAlB,EAA6B;AACnC,WAAOE,aAAP;AACA,GAFM,MAEA,IAAK,cAAcF,QAAnB,EAA8B;AACpC,WAAOG,cAAP;AACA;;AACD,SAAOC,aAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\theader as headerIcon,\n\tfooter as footerIcon,\n\tsidebar as sidebarIcon,\n\tlayout as layoutIcon,\n} from '@wordpress/icons';\n/**\n * Helper function to retrieve the corresponding icon by name.\n *\n * @param {string} iconName The name of the icon.\n *\n * @return {Object} The corresponding icon.\n */\nexport function getTemplatePartIcon( iconName ) {\n\tif ( 'header' === iconName ) {\n\t\treturn headerIcon;\n\t} else if ( 'footer' === iconName ) {\n\t\treturn footerIcon;\n\t} else if ( 'sidebar' === iconName ) {\n\t\treturn sidebarIcon;\n\t}\n\treturn layoutIcon;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/editor/src/store/utils/get-template-part-icon.js"],"names":["header","headerIcon","footer","footerIcon","sidebar","sidebarIcon","layout","layoutIcon","getTemplatePartIcon","iconName"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,MAAM,IAAIC,UADX,EAECC,MAAM,IAAIC,UAFX,EAGCC,OAAO,IAAIC,WAHZ,EAICC,MAAM,IAAIC,UAJX,QAKO,kBALP;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,mBAAT,CAA8BC,QAA9B,EAAyC;AAC/C,MAAK,aAAaA,QAAlB,EAA6B;AAC5B,WAAOR,UAAP;AACA,GAFD,MAEO,IAAK,aAAaQ,QAAlB,EAA6B;AACnC,WAAON,UAAP;AACA,GAFM,MAEA,IAAK,cAAcM,QAAnB,EAA8B;AACpC,WAAOJ,WAAP;AACA;;AACD,SAAOE,UAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\theader as headerIcon,\n\tfooter as footerIcon,\n\tsidebar as sidebarIcon,\n\tlayout as layoutIcon,\n} from '@wordpress/icons';\n/**\n * Helper function to retrieve the corresponding icon by name.\n *\n * @param {string} iconName The name of the icon.\n *\n * @return {Object} The corresponding icon.\n */\nexport function getTemplatePartIcon( iconName ) {\n\tif ( 'header' === iconName ) {\n\t\treturn headerIcon;\n\t} else if ( 'footer' === iconName ) {\n\t\treturn footerIcon;\n\t} else if ( 'sidebar' === iconName ) {\n\t\treturn sidebarIcon;\n\t}\n\treturn layoutIcon;\n}\n"]}