@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/editor",
3
- "version": "11.0.2",
3
+ "version": "12.0.0",
4
4
  "description": "Enhanced block editor for WordPress posts.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -31,34 +31,34 @@
31
31
  ],
32
32
  "dependencies": {
33
33
  "@babel/runtime": "^7.13.10",
34
- "@wordpress/a11y": "^3.2.2",
35
- "@wordpress/api-fetch": "^5.2.2",
36
- "@wordpress/autop": "^3.2.1",
34
+ "@wordpress/a11y": "^3.2.3",
35
+ "@wordpress/api-fetch": "^5.2.3",
36
+ "@wordpress/autop": "^3.2.2",
37
37
  "@wordpress/blob": "^3.2.1",
38
- "@wordpress/block-editor": "^7.0.2",
39
- "@wordpress/blocks": "^11.1.0",
40
- "@wordpress/components": "^17.0.0",
41
- "@wordpress/compose": "^5.0.2",
42
- "@wordpress/core-data": "^4.0.2",
43
- "@wordpress/data": "^6.1.0",
44
- "@wordpress/data-controls": "^2.2.3",
45
- "@wordpress/date": "^4.2.1",
46
- "@wordpress/deprecated": "^3.2.1",
47
- "@wordpress/element": "^4.0.1",
48
- "@wordpress/hooks": "^3.2.0",
49
- "@wordpress/html-entities": "^3.2.1",
50
- "@wordpress/i18n": "^4.2.2",
51
- "@wordpress/icons": "^5.0.2",
38
+ "@wordpress/block-editor": "^7.0.3",
39
+ "@wordpress/blocks": "^11.1.1",
40
+ "@wordpress/components": "^18.0.0",
41
+ "@wordpress/compose": "^5.0.3",
42
+ "@wordpress/core-data": "^4.0.3",
43
+ "@wordpress/data": "^6.1.1",
44
+ "@wordpress/data-controls": "^2.2.4",
45
+ "@wordpress/date": "^4.2.2",
46
+ "@wordpress/deprecated": "^3.2.2",
47
+ "@wordpress/element": "^4.0.2",
48
+ "@wordpress/hooks": "^3.2.1",
49
+ "@wordpress/html-entities": "^3.2.2",
50
+ "@wordpress/i18n": "^4.2.3",
51
+ "@wordpress/icons": "^6.0.0",
52
52
  "@wordpress/is-shallow-equal": "^4.2.0",
53
- "@wordpress/keyboard-shortcuts": "^3.0.2",
54
- "@wordpress/keycodes": "^3.2.2",
55
- "@wordpress/media-utils": "^3.0.1",
56
- "@wordpress/notices": "^3.2.3",
57
- "@wordpress/reusable-blocks": "^3.0.2",
58
- "@wordpress/rich-text": "^5.0.2",
59
- "@wordpress/server-side-render": "^3.0.2",
60
- "@wordpress/url": "^3.2.2",
61
- "@wordpress/wordcount": "^3.2.1",
53
+ "@wordpress/keyboard-shortcuts": "^3.0.3",
54
+ "@wordpress/keycodes": "^3.2.3",
55
+ "@wordpress/media-utils": "^3.0.2",
56
+ "@wordpress/notices": "^3.2.4",
57
+ "@wordpress/reusable-blocks": "^3.0.3",
58
+ "@wordpress/rich-text": "^5.0.3",
59
+ "@wordpress/server-side-render": "^3.0.3",
60
+ "@wordpress/url": "^3.2.3",
61
+ "@wordpress/wordcount": "^3.2.2",
62
62
  "classnames": "^2.3.1",
63
63
  "lodash": "^4.17.21",
64
64
  "memize": "^1.1.0",
@@ -68,5 +68,5 @@
68
68
  "publishConfig": {
69
69
  "access": "public"
70
70
  },
71
- "gitHead": "98c42a7187f788fe3e023f04df7f5dcbdae4e4e7"
71
+ "gitHead": "8f7f052bc04e3f4eb50f479ced14be1489b9fa79"
72
72
  }
@@ -10,8 +10,9 @@ import { count as characterCount } from '@wordpress/wordcount';
10
10
  import { store as editorStore } from '../../store';
11
11
 
12
12
  export default function CharacterCount() {
13
- const content = useSelect( ( select ) =>
14
- select( editorStore ).getEditedPostAttribute( 'content' )
13
+ const content = useSelect(
14
+ ( select ) => select( editorStore ).getEditedPostAttribute( 'content' ),
15
+ []
15
16
  );
16
17
 
17
18
  return characterCount( content, 'characters_including_spaces' );
@@ -0,0 +1,38 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { Pressable, Text } from 'react-native';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { usePreferredColorSchemeStyle } from '@wordpress/compose';
10
+
11
+ /**
12
+ * Internal dependencies
13
+ */
14
+ import styles from './style.scss';
15
+
16
+ const HelpGetSupportButton = ( { onPress, title } ) => {
17
+ const buttonStyle = usePreferredColorSchemeStyle(
18
+ styles.button,
19
+ styles.buttonDark
20
+ );
21
+
22
+ const textStyle = usePreferredColorSchemeStyle(
23
+ styles.buttonText,
24
+ styles.buttonTextDark
25
+ );
26
+
27
+ return (
28
+ <Pressable
29
+ style={ buttonStyle }
30
+ onPress={ onPress }
31
+ accessibilityRole={ 'button' }
32
+ >
33
+ <Text style={ textStyle }>{ title }</Text>
34
+ </Pressable>
35
+ );
36
+ };
37
+
38
+ export default HelpGetSupportButton;
@@ -2,7 +2,7 @@
2
2
  * External dependencies
3
3
  */
4
4
  import { kebabCase } from 'lodash';
5
- import { ScrollView, StyleSheet, View } from 'react-native';
5
+ import { Text, ScrollView, StyleSheet, View } from 'react-native';
6
6
  import { TransitionPresets } from '@react-navigation/stack';
7
7
 
8
8
  /**
@@ -23,6 +23,11 @@ import {
23
23
  } from '@wordpress/icons';
24
24
  import { useSelect } from '@wordpress/data';
25
25
  import { store as editorStore } from '@wordpress/editor';
26
+ import { usePreferredColorSchemeStyle } from '@wordpress/compose';
27
+ import {
28
+ requestContactCustomerSupport,
29
+ requestGotoCustomerSupportOptions,
30
+ } from '@wordpress/react-native-bridge';
26
31
 
27
32
  /**
28
33
  * Internal dependencies
@@ -30,6 +35,7 @@ import { store as editorStore } from '@wordpress/editor';
30
35
  import styles from './style.scss';
31
36
  import HelpDetailNavigationScreen from './help-detail-navigation-screen';
32
37
  import HelpTopicRow from './help-topic-row';
38
+ import HelpGetSupportButton from './help-get-support-button';
33
39
  import IntroToBlocks from './intro-to-blocks';
34
40
  import AddBlocks from './add-blocks';
35
41
  import MoveBlocks from './move-blocks';
@@ -61,6 +67,11 @@ function EditorHelpTopics( { close, isVisible, onClose } ) {
61
67
  postType: select( editorStore ).getEditedPostAttribute( 'type' ),
62
68
  } ) );
63
69
 
70
+ const sectionTitle = usePreferredColorSchemeStyle(
71
+ styles.helpDetailSectionHeading,
72
+ styles.helpDetailSectionHeadingDark
73
+ );
74
+
64
75
  const title =
65
76
  postType === 'page'
66
77
  ? __( 'How to edit your page' )
@@ -73,6 +84,7 @@ function EditorHelpTopics( { close, isVisible, onClose } ) {
73
84
  hideHeader
74
85
  hasNavigation
75
86
  contentStyle={ styles.contentContainer }
87
+ testID="editor-help-modal"
76
88
  >
77
89
  <BottomSheet.NavigationContainer animate main>
78
90
  <BottomSheet.NavigationScreen
@@ -113,6 +125,9 @@ function EditorHelpTopics( { close, isVisible, onClose } ) {
113
125
  } }
114
126
  >
115
127
  <PanelBody>
128
+ <Text style={ sectionTitle }>
129
+ { __( 'The basics' ) }
130
+ </Text>
116
131
  { /* Print out help topics */ }
117
132
  { HELP_TOPICS.map(
118
133
  ( { label, icon } ) => {
@@ -131,6 +146,31 @@ function EditorHelpTopics( { close, isVisible, onClose } ) {
131
146
  );
132
147
  }
133
148
  ) }
149
+ {
150
+ <Text style={ sectionTitle }>
151
+ { __( 'Get support' ) }
152
+ </Text>
153
+ }
154
+ {
155
+ <HelpGetSupportButton
156
+ title={ __(
157
+ 'Contact support'
158
+ ) }
159
+ onPress={
160
+ requestContactCustomerSupport
161
+ }
162
+ />
163
+ }
164
+ {
165
+ <HelpGetSupportButton
166
+ title={ __(
167
+ 'More support options'
168
+ ) }
169
+ onPress={
170
+ requestGotoCustomerSupportOptions
171
+ }
172
+ />
173
+ }
134
174
  </PanelBody>
135
175
  </ScrollView>
136
176
  );
@@ -0,0 +1,6 @@
1
+ @import "./style.scss";
2
+
3
+ .button {
4
+ border-radius: $border-width * 4;
5
+ padding: $grid-unit-10;
6
+ }
@@ -0,0 +1,6 @@
1
+ @import "./style.scss";
2
+
3
+ .button {
4
+ border-radius: $border-width * 8;
5
+ padding: $grid-unit-15;
6
+ }
@@ -1,3 +1,24 @@
1
+ .button {
2
+ margin: $grid-unit-10 $grid-unit-05;
3
+ align-items: center;
4
+ justify-content: center;
5
+ border: $border-width solid $gray-300;
6
+ }
7
+
8
+ .buttonDark {
9
+ border-color: $gray-700;
10
+ }
11
+
12
+ .buttonText {
13
+ font-weight: 600;
14
+ font-size: 16px;
15
+ color: $light-primary;
16
+ }
17
+
18
+ .buttonTextDark {
19
+ color: $dark-primary;
20
+ }
21
+
1
22
  .container {
2
23
  height: 100%;
3
24
  }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { fireEvent, render, waitForElementToBeRemoved } from 'test/helpers';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import EditorHelp from '../index';
10
+
11
+ it( 'lists help topics', async () => {
12
+ const screen = render( <EditorHelp isVisible /> );
13
+ const helpTopic = await screen.findByText( 'Customize blocks' );
14
+
15
+ expect( helpTopic ).toBeTruthy();
16
+ } );
17
+
18
+ it( 'navigates to help topic detail screen', async () => {
19
+ const screen = render( <EditorHelp isVisible /> );
20
+ const helpTopic = await screen.findByText( 'Customize blocks' );
21
+ fireEvent.press( helpTopic );
22
+
23
+ expect(
24
+ screen.getByText(
25
+ 'Each block has its own settings. To find them, tap on a block. Its settings will appear on the toolbar at the bottom of the screen.'
26
+ )
27
+ ).toBeTruthy();
28
+ } );
29
+
30
+ it( 'navigates back from help topic detail screen', async () => {
31
+ const screen = render( <EditorHelp isVisible /> );
32
+ const helpTopic = await screen.findByText( 'Customize blocks' );
33
+ fireEvent.press( helpTopic );
34
+
35
+ const backButton = screen.getAllByA11yLabel( 'Go back' );
36
+ fireEvent.press( backButton[ backButton.length - 1 ] );
37
+
38
+ // Currently logs `act` warning due to https://git.io/JYYGE
39
+ await waitForElementToBeRemoved( () =>
40
+ screen.getByText(
41
+ 'Each block has its own settings. To find them, tap on a block. Its settings will appear on the toolbar at the bottom of the screen.'
42
+ )
43
+ );
44
+ } );
45
+
46
+ it( 'dismisses when close button is pressed', async () => {
47
+ const closeMock = jest.fn();
48
+ const screen = render( <EditorHelp isVisible close={ closeMock } /> );
49
+ const closeButton = await screen.findByA11yLabel( 'Go back' );
50
+ fireEvent.press( closeButton );
51
+
52
+ expect( closeMock ).toHaveBeenCalled();
53
+ } );
54
+
55
+ it( 'dismisses when parent modal backdrop is pressed', async () => {
56
+ const onCloseMock = jest.fn();
57
+ const screen = render( <EditorHelp isVisible onClose={ onCloseMock } /> );
58
+ const modal = await screen.findByTestId( 'editor-help-modal' );
59
+ fireEvent( modal, 'backdropPress' );
60
+
61
+ expect( onCloseMock ).toHaveBeenCalled();
62
+ } );
63
+
64
+ it( 'dismisses when parent modal backdrop is swiped', async () => {
65
+ const onCloseMock = jest.fn();
66
+ const screen = render( <EditorHelp isVisible onClose={ onCloseMock } /> );
67
+ const modal = await screen.findByTestId( 'editor-help-modal' );
68
+ fireEvent( modal, 'swipeComplete' );
69
+
70
+ expect( onCloseMock ).toHaveBeenCalled();
71
+ } );
72
+
73
+ it( 'dismisses when hardware back button is pressed', async () => {
74
+ const onCloseMock = jest.fn();
75
+ const screen = render( <EditorHelp isVisible onClose={ onCloseMock } /> );
76
+ const modal = await screen.findByTestId( 'editor-help-modal' );
77
+ fireEvent( modal, 'backButtonPress' );
78
+
79
+ expect( onCloseMock ).toHaveBeenCalled();
80
+ } );
@@ -12,51 +12,43 @@ import { store as editorStore } from '../../store';
12
12
 
13
13
  function SaveShortcut( { resetBlocksOnSave } ) {
14
14
  const { resetEditorBlocks, savePost } = useDispatch( editorStore );
15
- const { isEditedPostDirty, getPostEdits } = useSelect( ( select ) => {
16
- const {
17
- isEditedPostDirty: _isEditedPostDirty,
18
- getPostEdits: _getPostEdits,
19
- } = select( editorStore );
20
-
21
- return {
22
- isEditedPostDirty: _isEditedPostDirty,
23
- getPostEdits: _getPostEdits,
24
- };
25
- }, [] );
26
-
27
- useShortcut(
28
- 'core/editor/save',
29
- ( event ) => {
30
- event.preventDefault();
31
-
32
- // TODO: This should be handled in the `savePost` effect in
33
- // considering `isSaveable`. See note on `isEditedPostSaveable`
34
- // selector about dirtiness and meta-boxes.
35
- //
36
- // See: `isEditedPostSaveable`
37
- if ( ! isEditedPostDirty() ) {
38
- return;
39
- }
15
+ const { isEditedPostDirty, getPostEdits, isPostSavingLocked } = useSelect(
16
+ editorStore
17
+ );
40
18
 
41
- // The text editor requires that editor blocks are updated for a
42
- // save to work correctly. Usually this happens when the textarea
43
- // for the code editors blurs, but the shortcut can be used without
44
- // blurring the textarea.
45
- if ( resetBlocksOnSave ) {
46
- const postEdits = getPostEdits();
47
- if (
48
- postEdits.content &&
49
- typeof postEdits.content === 'string'
50
- ) {
51
- const blocks = parse( postEdits.content );
52
- resetEditorBlocks( blocks );
53
- }
19
+ useShortcut( 'core/editor/save', ( event ) => {
20
+ event.preventDefault();
21
+
22
+ /**
23
+ * Do not save the post if post saving is locked.
24
+ */
25
+ if ( isPostSavingLocked() ) {
26
+ return;
27
+ }
28
+
29
+ // TODO: This should be handled in the `savePost` effect in
30
+ // considering `isSaveable`. See note on `isEditedPostSaveable`
31
+ // selector about dirtiness and meta-boxes.
32
+ //
33
+ // See: `isEditedPostSaveable`
34
+ if ( ! isEditedPostDirty() ) {
35
+ return;
36
+ }
37
+
38
+ // The text editor requires that editor blocks are updated for a
39
+ // save to work correctly. Usually this happens when the textarea
40
+ // for the code editors blurs, but the shortcut can be used without
41
+ // blurring the textarea.
42
+ if ( resetBlocksOnSave ) {
43
+ const postEdits = getPostEdits();
44
+ if ( postEdits.content && typeof postEdits.content === 'string' ) {
45
+ const blocks = parse( postEdits.content );
46
+ resetEditorBlocks( blocks );
54
47
  }
48
+ }
55
49
 
56
- savePost();
57
- },
58
- { bindGlobal: true }
59
- );
50
+ savePost();
51
+ } );
60
52
 
61
53
  return null;
62
54
  }
@@ -13,23 +13,15 @@ import { store as editorStore } from '../../store';
13
13
  function VisualEditorGlobalKeyboardShortcuts() {
14
14
  const { redo, undo } = useDispatch( editorStore );
15
15
 
16
- useShortcut(
17
- 'core/editor/undo',
18
- ( event ) => {
19
- undo();
20
- event.preventDefault();
21
- },
22
- { bindGlobal: true }
23
- );
16
+ useShortcut( 'core/editor/undo', ( event ) => {
17
+ undo();
18
+ event.preventDefault();
19
+ } );
24
20
 
25
- useShortcut(
26
- 'core/editor/redo',
27
- ( event ) => {
28
- redo();
29
- event.preventDefault();
30
- },
31
- { bindGlobal: true }
32
- );
21
+ useShortcut( 'core/editor/redo', ( event ) => {
22
+ redo();
23
+ event.preventDefault();
24
+ } );
33
25
 
34
26
  return <SaveShortcut />;
35
27
  }
@@ -6,7 +6,7 @@ import { find, get, includes, union } from 'lodash';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { __ } from '@wordpress/i18n';
9
+ import { __, sprintf } from '@wordpress/i18n';
10
10
  import { Button, SelectControl } from '@wordpress/components';
11
11
  import { useDispatch, useSelect } from '@wordpress/data';
12
12
  import { useInstanceId } from '@wordpress/compose';
@@ -107,7 +107,11 @@ export default function PostFormat() {
107
107
  onUpdatePostFormat( suggestion.id )
108
108
  }
109
109
  >
110
- { suggestion.caption }
110
+ { sprintf(
111
+ /* translators: %s: post format */
112
+ __( 'Apply format: %s' ),
113
+ suggestion.caption
114
+ ) }
111
115
  </Button>
112
116
  </div>
113
117
  ) }
@@ -12,6 +12,7 @@
12
12
  }
13
13
 
14
14
  .editor-post-format__suggestion {
15
+ padding: $grid-unit-15 * 0.5;
15
16
  text-align: right;
16
17
  font-size: $default-font-size;
17
18
  }
@@ -54,7 +54,7 @@ export default function PostLockedModal() {
54
54
  activePostLock: getActivePostLock(),
55
55
  postType: getPostType( getEditedPostAttribute( 'type' ) ),
56
56
  };
57
- } );
57
+ }, [] );
58
58
 
59
59
  useEffect( () => {
60
60
  /**
@@ -100,79 +100,65 @@ export default function PostSavedState( {
100
100
  return () => clearTimeout( timeoutId );
101
101
  }, [ isSaving ] );
102
102
 
103
- if ( isSaving ) {
104
- // TODO: Classes generation should be common across all return
105
- // paths of this function, including proper naming convention for
106
- // the "Save Draft" button.
107
- const classes = classnames(
108
- 'editor-post-saved-state',
109
- 'is-saving',
110
- getAnimateClassName( { type: 'loading' } ),
111
- {
112
- 'is-autosaving': isAutosaving,
113
- }
114
- );
115
-
116
- return (
117
- <span className={ classes }>
118
- <Icon icon={ cloud } />
119
- { isAutosaving ? __( 'Autosaving' ) : __( 'Saving' ) }
120
- </span>
121
- );
122
- }
123
-
124
- if ( isPublished || isScheduled ) {
125
- return <PostSwitchToDraftButton />;
126
- }
127
-
128
- if ( ! isSaveable ) {
129
- return null;
130
- }
131
-
132
- if ( forceSavedMessage || ( ! isNew && ! isDirty ) ) {
133
- return (
134
- <span className="editor-post-saved-state is-saved">
135
- <Icon icon={ check } />
136
- { __( 'Saved' ) }
137
- </span>
138
- );
139
- }
140
-
141
103
  // Once the post has been submitted for review this button
142
104
  // is not needed for the contributor role.
143
-
144
105
  if ( ! hasPublishAction && isPending ) {
145
106
  return null;
146
107
  }
147
108
 
109
+ if ( isPublished || isScheduled ) {
110
+ return <PostSwitchToDraftButton />;
111
+ }
112
+
148
113
  /* translators: button label text should, if possible, be under 16 characters. */
149
114
  const label = isPending ? __( 'Save as pending' ) : __( 'Save draft' );
150
115
 
151
116
  /* translators: button label text should, if possible, be under 16 characters. */
152
117
  const shortLabel = __( 'Save' );
153
118
 
154
- if ( ! isLargeViewport ) {
155
- return (
156
- <Button
157
- className="editor-post-save-draft"
158
- label={ label }
159
- onClick={ () => savePost() }
160
- shortcut={ displayShortcut.primary( 's' ) }
161
- icon={ cloudUpload }
162
- >
163
- { showIconLabels && shortLabel }
164
- </Button>
165
- );
119
+ const isSaved = forceSavedMessage || ( ! isNew && ! isDirty );
120
+ const isSavedState = isSaving || isSaved;
121
+ const isDisabled = isSaving || isSaved || ! isSaveable;
122
+
123
+ let text;
124
+
125
+ if ( isSaving ) {
126
+ text = isAutosaving ? __( 'Autosaving' ) : __( 'Saving' );
127
+ } else if ( isSaved ) {
128
+ text = __( 'Saved' );
129
+ } else if ( isLargeViewport ) {
130
+ text = label;
131
+ } else if ( showIconLabels ) {
132
+ text = shortLabel;
166
133
  }
167
134
 
135
+ // Use common Button instance for all saved states so that focus is not
136
+ // lost.
168
137
  return (
169
138
  <Button
170
- className="editor-post-save-draft"
171
- onClick={ () => savePost() }
139
+ className={
140
+ isSaveable || isSaving
141
+ ? classnames( {
142
+ 'editor-post-save-draft': ! isSavedState,
143
+ 'editor-post-saved-state': isSavedState,
144
+ 'is-saving': isSaving,
145
+ 'is-autosaving': isAutosaving,
146
+ 'is-saved': isSaved,
147
+ [ getAnimateClassName( {
148
+ type: 'loading',
149
+ } ) ]: isSaving,
150
+ } )
151
+ : undefined
152
+ }
153
+ onClick={ isDisabled ? undefined : () => savePost() }
172
154
  shortcut={ displayShortcut.primary( 's' ) }
173
- variant="tertiary"
155
+ variant={ isLargeViewport ? 'tertiary' : undefined }
156
+ icon={ isLargeViewport ? undefined : cloudUpload }
157
+ label={ label }
158
+ aria-disabled={ isDisabled }
174
159
  >
175
- { label }
160
+ { isSavedState && <Icon icon={ isSaved ? check : cloud } /> }
161
+ { text }
176
162
  </Button>
177
163
  );
178
164
  }
@@ -7,6 +7,13 @@
7
7
  overflow: hidden;
8
8
  white-space: nowrap;
9
9
 
10
+ // The disabled version of the save state should be legible as an indicator.
11
+ &.is-saved[aria-disabled="true"],
12
+ &.is-saved[aria-disabled="true"]:hover {
13
+ background: transparent;
14
+ color: $gray-700;
15
+ }
16
+
10
17
  svg {
11
18
  display: inline-block;
12
19
  flex: 0 0 auto;
@@ -20,7 +27,7 @@
20
27
  text-indent: inherit;
21
28
 
22
29
  svg {
23
- margin-right: $grid-unit-05;
30
+ margin-right: 0;
24
31
  }
25
32
  }
26
33
  }
@@ -1,10 +1,30 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
+ exports[`PostSavedState returns a disabled button if the post is not saveable 1`] = `
4
+ <ForwardRef(Button)
5
+ aria-disabled={true}
6
+ icon={
7
+ <SVG
8
+ viewBox="0 0 24 24"
9
+ xmlns="http://www.w3.org/2000/svg"
10
+ >
11
+ <Path
12
+ d="M17.3 10.1c0-2.5-2.1-4.4-4.8-4.4-2.2 0-4.1 1.4-4.6 3.3h-.2C5.7 9 4 10.7 4 12.8c0 2.1 1.7 3.8 3.7 3.8h9c1.8 0 3.2-1.5 3.2-3.3.1-1.6-1.1-2.9-2.6-3.2zm-.5 5.1h-4v-2.4L14 14l1-1-3-3-3 3 1 1 1.2-1.2v2.4H7.7c-1.2 0-2.2-1.1-2.2-2.3s1-2.4 2.2-2.4H9l.3-1.1c.4-1.3 1.7-2.2 3.2-2.2 1.8 0 3.3 1.3 3.3 2.9v1.3l1.3.2c.8.1 1.4.9 1.4 1.8 0 1-.8 1.8-1.7 1.8z"
13
+ />
14
+ </SVG>
15
+ }
16
+ label="Save draft"
17
+ shortcut="Ctrl+S"
18
+ />
19
+ `;
20
+
3
21
  exports[`PostSavedState returns a switch to draft link if the post is published 1`] = `<WithSelect(WithDispatch(PostSwitchToDraftButton)) />`;
4
22
 
5
23
  exports[`PostSavedState should return Save button if edits to be saved 1`] = `
6
24
  <ForwardRef(Button)
25
+ aria-disabled={false}
7
26
  className="editor-post-save-draft"
27
+ label="Save draft"
8
28
  onClick={[Function]}
9
29
  shortcut="Ctrl+S"
10
30
  variant="tertiary"