@wordpress/edit-site 3.0.26 → 3.0.27

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 (120) hide show
  1. package/build/components/add-new-template/new-template-part.js +4 -1
  2. package/build/components/add-new-template/new-template-part.js.map +1 -1
  3. package/build/components/error-boundary/index.js +11 -27
  4. package/build/components/error-boundary/index.js.map +1 -1
  5. package/build/components/error-boundary/warning.js +70 -0
  6. package/build/components/error-boundary/warning.js.map +1 -0
  7. package/build/components/global-styles/screen-background-color.js +8 -9
  8. package/build/components/global-styles/screen-background-color.js.map +1 -1
  9. package/build/components/global-styles/screen-link-color.js +6 -10
  10. package/build/components/global-styles/screen-link-color.js.map +1 -1
  11. package/build/components/global-styles/screen-text-color.js +6 -10
  12. package/build/components/global-styles/screen-text-color.js.map +1 -1
  13. package/build/components/header/more-menu/index.js +68 -39
  14. package/build/components/header/more-menu/index.js.map +1 -1
  15. package/build/{plugins → components/header/more-menu}/site-export.js +0 -0
  16. package/build/components/header/more-menu/site-export.js.map +1 -0
  17. package/build/{plugins → components/header/more-menu}/welcome-guide-menu-item.js +1 -1
  18. package/build/components/header/more-menu/welcome-guide-menu-item.js.map +1 -0
  19. package/build/components/header/tools-more-menu-group/index.js +1 -5
  20. package/build/components/header/tools-more-menu-group/index.js.map +1 -1
  21. package/build/components/keyboard-shortcut-help-modal/config.js +45 -0
  22. package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -0
  23. package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +56 -0
  24. package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -0
  25. package/build/components/keyboard-shortcut-help-modal/index.js +137 -0
  26. package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -0
  27. package/build/components/keyboard-shortcut-help-modal/shortcut.js +65 -0
  28. package/build/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -0
  29. package/build/components/keyboard-shortcuts/index.js +9 -0
  30. package/build/components/keyboard-shortcuts/index.js.map +1 -1
  31. package/build/components/list/added-by.js +51 -50
  32. package/build/components/list/added-by.js.map +1 -1
  33. package/build/components/routes/redirect-to-homepage.js +106 -0
  34. package/build/components/routes/redirect-to-homepage.js.map +1 -0
  35. package/build/components/template-part-converter/convert-to-template-part.js +4 -1
  36. package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
  37. package/build/components/url-query-controller/index.js +1 -38
  38. package/build/components/url-query-controller/index.js.map +1 -1
  39. package/build/index.js +23 -4
  40. package/build/index.js.map +1 -1
  41. package/build/store/actions.js +7 -25
  42. package/build/store/actions.js.map +1 -1
  43. package/build-module/components/add-new-template/new-template-part.js +4 -1
  44. package/build-module/components/add-new-template/new-template-part.js.map +1 -1
  45. package/build-module/components/error-boundary/index.js +9 -26
  46. package/build-module/components/error-boundary/index.js.map +1 -1
  47. package/build-module/components/error-boundary/warning.js +60 -0
  48. package/build-module/components/error-boundary/warning.js.map +1 -0
  49. package/build-module/components/global-styles/screen-background-color.js +8 -10
  50. package/build-module/components/global-styles/screen-background-color.js.map +1 -1
  51. package/build-module/components/global-styles/screen-link-color.js +7 -11
  52. package/build-module/components/global-styles/screen-link-color.js.map +1 -1
  53. package/build-module/components/global-styles/screen-text-color.js +7 -11
  54. package/build-module/components/global-styles/screen-text-color.js.map +1 -1
  55. package/build-module/components/header/more-menu/index.js +65 -40
  56. package/build-module/components/header/more-menu/index.js.map +1 -1
  57. package/build-module/{plugins → components/header/more-menu}/site-export.js +0 -0
  58. package/build-module/components/header/more-menu/site-export.js.map +1 -0
  59. package/build-module/{plugins → components/header/more-menu}/welcome-guide-menu-item.js +1 -1
  60. package/build-module/components/header/more-menu/welcome-guide-menu-item.js.map +1 -0
  61. package/build-module/components/header/tools-more-menu-group/index.js +2 -5
  62. package/build-module/components/header/tools-more-menu-group/index.js.map +1 -1
  63. package/build-module/components/keyboard-shortcut-help-modal/config.js +36 -0
  64. package/build-module/components/keyboard-shortcut-help-modal/config.js.map +1 -0
  65. package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +44 -0
  66. package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -0
  67. package/build-module/components/keyboard-shortcut-help-modal/index.js +120 -0
  68. package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -0
  69. package/build-module/components/keyboard-shortcut-help-modal/shortcut.js +58 -0
  70. package/build-module/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -0
  71. package/build-module/components/keyboard-shortcuts/index.js +9 -0
  72. package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
  73. package/build-module/components/list/added-by.js +52 -51
  74. package/build-module/components/list/added-by.js.map +1 -1
  75. package/build-module/components/routes/redirect-to-homepage.js +94 -0
  76. package/build-module/components/routes/redirect-to-homepage.js.map +1 -0
  77. package/build-module/components/template-part-converter/convert-to-template-part.js +4 -1
  78. package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
  79. package/build-module/components/url-query-controller/index.js +3 -40
  80. package/build-module/components/url-query-controller/index.js.map +1 -1
  81. package/build-module/index.js +20 -3
  82. package/build-module/index.js.map +1 -1
  83. package/build-module/store/actions.js +7 -23
  84. package/build-module/store/actions.js.map +1 -1
  85. package/build-style/style-rtl.css +51 -0
  86. package/build-style/style.css +51 -0
  87. package/package.json +9 -9
  88. package/src/components/add-new-template/new-template-part.js +7 -1
  89. package/src/components/error-boundary/index.js +11 -28
  90. package/src/components/error-boundary/warning.js +59 -0
  91. package/src/components/global-styles/screen-background-color.js +6 -9
  92. package/src/components/global-styles/screen-link-color.js +6 -14
  93. package/src/components/global-styles/screen-text-color.js +6 -14
  94. package/src/components/header/more-menu/index.js +103 -44
  95. package/src/{plugins → components/header/more-menu}/site-export.js +0 -0
  96. package/src/{plugins → components/header/more-menu}/welcome-guide-menu-item.js +1 -1
  97. package/src/components/header/tools-more-menu-group/index.js +2 -7
  98. package/src/components/keyboard-shortcut-help-modal/config.js +27 -0
  99. package/src/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +41 -0
  100. package/src/components/keyboard-shortcut-help-modal/index.js +135 -0
  101. package/src/components/keyboard-shortcut-help-modal/shortcut.js +73 -0
  102. package/src/components/keyboard-shortcut-help-modal/style.scss +66 -0
  103. package/src/components/keyboard-shortcuts/index.js +10 -0
  104. package/src/components/list/added-by.js +57 -63
  105. package/src/components/routes/redirect-to-homepage.js +94 -0
  106. package/src/components/template-part-converter/convert-to-template-part.js +6 -1
  107. package/src/components/url-query-controller/index.js +3 -35
  108. package/src/index.js +25 -2
  109. package/src/store/actions.js +7 -35
  110. package/src/store/test/actions.js +0 -90
  111. package/src/style.scss +1 -0
  112. package/build/plugins/index.js +0 -28
  113. package/build/plugins/index.js.map +0 -1
  114. package/build/plugins/site-export.js.map +0 -1
  115. package/build/plugins/welcome-guide-menu-item.js.map +0 -1
  116. package/build-module/plugins/index.js +0 -20
  117. package/build-module/plugins/index.js.map +0 -1
  118. package/build-module/plugins/site-export.js.map +0 -1
  119. package/build-module/plugins/welcome-guide-menu-item.js.map +0 -1
  120. package/src/plugins/index.js +0 -24
@@ -2,7 +2,7 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { __ } from '@wordpress/i18n';
5
- import { __experimentalPanelColorGradientSettings as PanelColorGradientSettings } from '@wordpress/block-editor';
5
+ import { __experimentalColorGradientControl as ColorGradientControl } from '@wordpress/block-editor';
6
6
 
7
7
  /**
8
8
  * Internal dependencies
@@ -55,7 +55,6 @@ function ScreenBackgroundColor( { name } ) {
55
55
  return null;
56
56
  }
57
57
 
58
- const settings = [];
59
58
  let backgroundSettings = {};
60
59
  if ( hasBackgroundColor ) {
61
60
  backgroundSettings = {
@@ -79,11 +78,10 @@ function ScreenBackgroundColor( { name } ) {
79
78
  }
80
79
  }
81
80
 
82
- settings.push( {
81
+ const controlProps = {
83
82
  ...backgroundSettings,
84
83
  ...gradientSettings,
85
- label: __( 'Background color' ),
86
- } );
84
+ };
87
85
 
88
86
  return (
89
87
  <>
@@ -94,10 +92,8 @@ function ScreenBackgroundColor( { name } ) {
94
92
  'Set a background color or gradient for the whole website.'
95
93
  ) }
96
94
  />
97
-
98
- <PanelColorGradientSettings
99
- title={ __( 'Color' ) }
100
- settings={ settings }
95
+ <ColorGradientControl
96
+ className="edit-site-screen-background-color__control"
101
97
  colors={ colorsPerOrigin }
102
98
  gradients={ gradientsPerOrigin }
103
99
  disableCustomColors={ ! areCustomSolidsEnabled }
@@ -106,6 +102,7 @@ function ScreenBackgroundColor( { name } ) {
106
102
  showTitle={ false }
107
103
  enableAlpha
108
104
  __experimentalIsRenderedInSidebar
105
+ { ...controlProps }
109
106
  />
110
107
  </>
111
108
  );
@@ -2,7 +2,7 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { __ } from '@wordpress/i18n';
5
- import { __experimentalPanelColorGradientSettings as PanelColorGradientSettings } from '@wordpress/block-editor';
5
+ import { __experimentalColorGradientControl as ColorGradientControl } from '@wordpress/block-editor';
6
6
 
7
7
  /**
8
8
  * Internal dependencies
@@ -44,15 +44,6 @@ function ScreenLinkColor( { name } ) {
44
44
  return null;
45
45
  }
46
46
 
47
- const settings = [
48
- {
49
- colorValue: linkColor,
50
- onColorChange: setLinkColor,
51
- label: __( 'Link color' ),
52
- clearable: linkColor === userLinkColor,
53
- },
54
- ];
55
-
56
47
  return (
57
48
  <>
58
49
  <ScreenHeader
@@ -62,16 +53,17 @@ function ScreenLinkColor( { name } ) {
62
53
  'Set the default color used for links across the site.'
63
54
  ) }
64
55
  />
65
-
66
- <PanelColorGradientSettings
67
- title={ __( 'Color' ) }
68
- settings={ settings }
56
+ <ColorGradientControl
57
+ className="edit-site-screen-link-color__control"
69
58
  colors={ colorsPerOrigin }
70
59
  disableCustomColors={ ! areCustomSolidsEnabled }
71
60
  __experimentalHasMultipleOrigins
72
61
  showTitle={ false }
73
62
  enableAlpha
74
63
  __experimentalIsRenderedInSidebar
64
+ colorValue={ linkColor }
65
+ onColorChange={ setLinkColor }
66
+ clearable={ linkColor === userLinkColor }
75
67
  />
76
68
  </>
77
69
  );
@@ -2,7 +2,7 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { __ } from '@wordpress/i18n';
5
- import { __experimentalPanelColorGradientSettings as PanelColorGradientSettings } from '@wordpress/block-editor';
5
+ import { __experimentalColorGradientControl as ColorGradientControl } from '@wordpress/block-editor';
6
6
 
7
7
  /**
8
8
  * Internal dependencies
@@ -36,15 +36,6 @@ function ScreenTextColor( { name } ) {
36
36
  return null;
37
37
  }
38
38
 
39
- const settings = [
40
- {
41
- colorValue: color,
42
- onColorChange: setColor,
43
- label: __( 'Text color' ),
44
- clearable: color === userColor,
45
- },
46
- ];
47
-
48
39
  return (
49
40
  <>
50
41
  <ScreenHeader
@@ -54,16 +45,17 @@ function ScreenTextColor( { name } ) {
54
45
  'Set the default color used for text across the site.'
55
46
  ) }
56
47
  />
57
-
58
- <PanelColorGradientSettings
59
- title={ __( 'Color' ) }
60
- settings={ settings }
48
+ <ColorGradientControl
49
+ className="edit-site-screen-text-color__control"
61
50
  colors={ colorsPerOrigin }
62
51
  disableCustomColors={ ! areCustomSolidsEnabled }
63
52
  __experimentalHasMultipleOrigins
64
53
  showTitle={ false }
65
54
  enableAlpha
66
55
  __experimentalIsRenderedInSidebar
56
+ colorValue={ color }
57
+ onColorChange={ setColor }
58
+ clearable={ color === userColor }
67
59
  />
68
60
  </>
69
61
  );
@@ -2,15 +2,26 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { __, _x } from '@wordpress/i18n';
5
- import { moreVertical } from '@wordpress/icons';
6
- import { DropdownMenu, MenuGroup } from '@wordpress/components';
5
+ import { useReducer } from '@wordpress/element';
6
+ import { useShortcut } from '@wordpress/keyboard-shortcuts';
7
+ import { displayShortcut } from '@wordpress/keycodes';
8
+ import { external, moreVertical } from '@wordpress/icons';
9
+ import {
10
+ DropdownMenu,
11
+ MenuGroup,
12
+ MenuItem,
13
+ VisuallyHidden,
14
+ } from '@wordpress/components';
7
15
  import { ActionItem } from '@wordpress/interface';
8
16
 
9
17
  /**
10
18
  * Internal dependencies
11
19
  */
20
+ import KeyboardShortcutHelpModal from '../../keyboard-shortcut-help-modal';
12
21
  import FeatureToggle from '../feature-toggle';
13
22
  import ToolsMoreMenuGroup from '../tools-more-menu-group';
23
+ import SiteExport from './site-export';
24
+ import WelcomeGuideMenuItem from './welcome-guide-menu-item';
14
25
 
15
26
  const POPOVER_PROPS = {
16
27
  className: 'edit-site-more-menu__content',
@@ -20,46 +31,94 @@ const TOGGLE_PROPS = {
20
31
  tooltipPosition: 'bottom',
21
32
  };
22
33
 
23
- const MoreMenu = () => (
24
- <DropdownMenu
25
- className="edit-site-more-menu"
26
- icon={ moreVertical }
27
- label={ __( 'More tools & options' ) }
28
- popoverProps={ POPOVER_PROPS }
29
- toggleProps={ TOGGLE_PROPS }
30
- >
31
- { ( { onClose } ) => (
32
- <>
33
- <MenuGroup label={ _x( 'View', 'noun' ) }>
34
- <FeatureToggle
35
- feature="fixedToolbar"
36
- label={ __( 'Top toolbar' ) }
37
- info={ __(
38
- 'Access all block and document tools in a single place'
39
- ) }
40
- messageActivated={ __( 'Top toolbar activated' ) }
41
- messageDeactivated={ __( 'Top toolbar deactivated' ) }
42
- />
43
- <FeatureToggle
44
- feature="focusMode"
45
- label={ __( 'Spotlight mode' ) }
46
- info={ __( 'Focus on one block at a time' ) }
47
- messageActivated={ __( 'Spotlight mode activated' ) }
48
- messageDeactivated={ __(
49
- 'Spotlight mode deactivated'
50
- ) }
51
- />
52
- <ActionItem.Slot
53
- name="core/edit-site/plugin-more-menu"
54
- label={ __( 'Plugins' ) }
55
- as={ MenuGroup }
56
- fillProps={ { onClick: onClose } }
57
- />
58
- </MenuGroup>
59
- <ToolsMoreMenuGroup.Slot fillProps={ { onClose } } />
60
- </>
61
- ) }
62
- </DropdownMenu>
63
- );
34
+ export default function MoreMenu() {
35
+ const [ isModalActive, toggleModal ] = useReducer(
36
+ ( isActive ) => ! isActive,
37
+ false
38
+ );
64
39
 
65
- export default MoreMenu;
40
+ useShortcut( 'core/edit-site/keyboard-shortcuts', toggleModal );
41
+
42
+ return (
43
+ <>
44
+ <DropdownMenu
45
+ className="edit-site-more-menu"
46
+ icon={ moreVertical }
47
+ label={ __( 'More tools & options' ) }
48
+ popoverProps={ POPOVER_PROPS }
49
+ toggleProps={ TOGGLE_PROPS }
50
+ >
51
+ { ( { onClose } ) => (
52
+ <>
53
+ <MenuGroup label={ _x( 'View', 'noun' ) }>
54
+ <FeatureToggle
55
+ feature="fixedToolbar"
56
+ label={ __( 'Top toolbar' ) }
57
+ info={ __(
58
+ 'Access all block and document tools in a single place'
59
+ ) }
60
+ messageActivated={ __(
61
+ 'Top toolbar activated'
62
+ ) }
63
+ messageDeactivated={ __(
64
+ 'Top toolbar deactivated'
65
+ ) }
66
+ />
67
+ <FeatureToggle
68
+ feature="focusMode"
69
+ label={ __( 'Spotlight mode' ) }
70
+ info={ __( 'Focus on one block at a time' ) }
71
+ messageActivated={ __(
72
+ 'Spotlight mode activated'
73
+ ) }
74
+ messageDeactivated={ __(
75
+ 'Spotlight mode deactivated'
76
+ ) }
77
+ />
78
+ <ActionItem.Slot
79
+ name="core/edit-site/plugin-more-menu"
80
+ label={ __( 'Plugins' ) }
81
+ as={ MenuGroup }
82
+ fillProps={ { onClick: onClose } }
83
+ />
84
+ </MenuGroup>
85
+ <MenuGroup label={ __( 'Tools' ) }>
86
+ <SiteExport />
87
+ <MenuItem
88
+ onClick={ toggleModal }
89
+ shortcut={ displayShortcut.access( 'h' ) }
90
+ >
91
+ { __( 'Keyboard shortcuts' ) }
92
+ </MenuItem>
93
+ <WelcomeGuideMenuItem />
94
+ <MenuItem
95
+ icon={ external }
96
+ role="menuitem"
97
+ href={ __(
98
+ 'https://wordpress.org/support/article/site-editor/'
99
+ ) }
100
+ target="_blank"
101
+ rel="noopener noreferrer"
102
+ >
103
+ { __( 'Help' ) }
104
+ <VisuallyHidden as="span">
105
+ {
106
+ /* translators: accessibility text */
107
+ __( '(opens in a new tab)' )
108
+ }
109
+ </VisuallyHidden>
110
+ </MenuItem>
111
+ <ToolsMoreMenuGroup.Slot
112
+ fillProps={ { onClose } }
113
+ />
114
+ </MenuGroup>
115
+ </>
116
+ ) }
117
+ </DropdownMenu>
118
+ <KeyboardShortcutHelpModal
119
+ isModalActive={ isModalActive }
120
+ toggleModal={ toggleModal }
121
+ />
122
+ </>
123
+ );
124
+ }
@@ -8,7 +8,7 @@ import { MenuItem } from '@wordpress/components';
8
8
  /**
9
9
  * Internal dependencies
10
10
  */
11
- import { store as editSiteStore } from '../store';
11
+ import { store as editSiteStore } from '../../../store';
12
12
 
13
13
  export default function WelcomeGuideMenuItem() {
14
14
  const { toggleFeature } = useDispatch( editSiteStore );
@@ -6,8 +6,7 @@ import { isEmpty } from 'lodash';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { createSlotFill, MenuGroup } from '@wordpress/components';
10
- import { __ } from '@wordpress/i18n';
9
+ import { createSlotFill } from '@wordpress/components';
11
10
 
12
11
  const { Fill: ToolsMoreMenuGroup, Slot } = createSlotFill(
13
12
  'EditSiteToolsMoreMenuGroup'
@@ -15,11 +14,7 @@ const { Fill: ToolsMoreMenuGroup, Slot } = createSlotFill(
15
14
 
16
15
  ToolsMoreMenuGroup.Slot = ( { fillProps } ) => (
17
16
  <Slot fillProps={ fillProps }>
18
- { ( fills ) =>
19
- ! isEmpty( fills ) && (
20
- <MenuGroup label={ __( 'Tools' ) }>{ fills }</MenuGroup>
21
- )
22
- }
17
+ { ( fills ) => ! isEmpty( fills ) && fills }
23
18
  </Slot>
24
19
  );
25
20
 
@@ -0,0 +1,27 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+
6
+ export const textFormattingShortcuts = [
7
+ {
8
+ keyCombination: { modifier: 'primary', character: 'b' },
9
+ description: __( 'Make the selected text bold.' ),
10
+ },
11
+ {
12
+ keyCombination: { modifier: 'primary', character: 'i' },
13
+ description: __( 'Make the selected text italic.' ),
14
+ },
15
+ {
16
+ keyCombination: { modifier: 'primary', character: 'k' },
17
+ description: __( 'Convert the selected text into a link.' ),
18
+ },
19
+ {
20
+ keyCombination: { modifier: 'primaryShift', character: 'k' },
21
+ description: __( 'Remove a link.' ),
22
+ },
23
+ {
24
+ keyCombination: { modifier: 'primary', character: 'u' },
25
+ description: __( 'Underline the selected text.' ),
26
+ },
27
+ ];
@@ -0,0 +1,41 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useSelect } from '@wordpress/data';
5
+ import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import Shortcut from './shortcut';
11
+
12
+ export default function DynamicShortcut( { name } ) {
13
+ const { keyCombination, description, aliases } = useSelect(
14
+ ( select ) => {
15
+ const {
16
+ getShortcutKeyCombination,
17
+ getShortcutDescription,
18
+ getShortcutAliases,
19
+ } = select( keyboardShortcutsStore );
20
+
21
+ return {
22
+ keyCombination: getShortcutKeyCombination( name ),
23
+ aliases: getShortcutAliases( name ),
24
+ description: getShortcutDescription( name ),
25
+ };
26
+ },
27
+ [ name ]
28
+ );
29
+
30
+ if ( ! keyCombination ) {
31
+ return null;
32
+ }
33
+
34
+ return (
35
+ <Shortcut
36
+ keyCombination={ keyCombination }
37
+ description={ description }
38
+ aliases={ aliases }
39
+ />
40
+ );
41
+ }
@@ -0,0 +1,135 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import classnames from 'classnames';
5
+ import { isString } from 'lodash';
6
+
7
+ /**
8
+ * WordPress dependencies
9
+ */
10
+ import { Modal } from '@wordpress/components';
11
+ import { __ } from '@wordpress/i18n';
12
+ import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
13
+ import { useSelect } from '@wordpress/data';
14
+
15
+ /**
16
+ * Internal dependencies
17
+ */
18
+ import { textFormattingShortcuts } from './config';
19
+ import Shortcut from './shortcut';
20
+ import DynamicShortcut from './dynamic-shortcut';
21
+
22
+ const ShortcutList = ( { shortcuts } ) => (
23
+ /*
24
+ * Disable reason: The `list` ARIA role is redundant but
25
+ * Safari+VoiceOver won't announce the list otherwise.
26
+ */
27
+ /* eslint-disable jsx-a11y/no-redundant-roles */
28
+ <ul
29
+ className="edit-site-keyboard-shortcut-help-modal__shortcut-list"
30
+ role="list"
31
+ >
32
+ { shortcuts.map( ( shortcut, index ) => (
33
+ <li
34
+ className="edit-site-keyboard-shortcut-help-modal__shortcut"
35
+ key={ index }
36
+ >
37
+ { isString( shortcut ) ? (
38
+ <DynamicShortcut name={ shortcut } />
39
+ ) : (
40
+ <Shortcut { ...shortcut } />
41
+ ) }
42
+ </li>
43
+ ) ) }
44
+ </ul>
45
+ /* eslint-enable jsx-a11y/no-redundant-roles */
46
+ );
47
+
48
+ const ShortcutSection = ( { title, shortcuts, className } ) => (
49
+ <section
50
+ className={ classnames(
51
+ 'edit-site-keyboard-shortcut-help-modal__section',
52
+ className
53
+ ) }
54
+ >
55
+ { !! title && (
56
+ <h2 className="edit-site-keyboard-shortcut-help-modal__section-title">
57
+ { title }
58
+ </h2>
59
+ ) }
60
+ <ShortcutList shortcuts={ shortcuts } />
61
+ </section>
62
+ );
63
+
64
+ const ShortcutCategorySection = ( {
65
+ title,
66
+ categoryName,
67
+ additionalShortcuts = [],
68
+ } ) => {
69
+ const categoryShortcuts = useSelect(
70
+ ( select ) => {
71
+ return select( keyboardShortcutsStore ).getCategoryShortcuts(
72
+ categoryName
73
+ );
74
+ },
75
+ [ categoryName ]
76
+ );
77
+
78
+ return (
79
+ <ShortcutSection
80
+ title={ title }
81
+ shortcuts={ categoryShortcuts.concat( additionalShortcuts ) }
82
+ />
83
+ );
84
+ };
85
+
86
+ export default function KeyboardShortcutHelpModal( {
87
+ isModalActive,
88
+ toggleModal,
89
+ } ) {
90
+ if ( ! isModalActive ) {
91
+ return null;
92
+ }
93
+
94
+ return (
95
+ <Modal
96
+ className="edit-site-keyboard-shortcut-help-modal"
97
+ title={ __( 'Keyboard shortcuts' ) }
98
+ closeLabel={ __( 'Close' ) }
99
+ onRequestClose={ toggleModal }
100
+ >
101
+ <ShortcutSection
102
+ className="edit-site-keyboard-shortcut-help-modal__main-shortcuts"
103
+ shortcuts={ [ 'core/edit-site/keyboard-shortcuts' ] }
104
+ />
105
+ <ShortcutCategorySection
106
+ title={ __( 'Global shortcuts' ) }
107
+ categoryName="global"
108
+ />
109
+
110
+ <ShortcutCategorySection
111
+ title={ __( 'Selection shortcuts' ) }
112
+ categoryName="selection"
113
+ />
114
+
115
+ <ShortcutCategorySection
116
+ title={ __( 'Block shortcuts' ) }
117
+ categoryName="block"
118
+ additionalShortcuts={ [
119
+ {
120
+ keyCombination: { character: '/' },
121
+ description: __(
122
+ 'Change the block type after adding a new paragraph.'
123
+ ),
124
+ /* translators: The forward-slash character. e.g. '/'. */
125
+ ariaLabel: __( 'Forward-slash' ),
126
+ },
127
+ ] }
128
+ />
129
+ <ShortcutSection
130
+ title={ __( 'Text formatting' ) }
131
+ shortcuts={ textFormattingShortcuts }
132
+ />
133
+ </Modal>
134
+ );
135
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { castArray } from 'lodash';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { Fragment } from '@wordpress/element';
10
+ import { displayShortcutList, shortcutAriaLabel } from '@wordpress/keycodes';
11
+
12
+ function KeyCombination( { keyCombination, forceAriaLabel } ) {
13
+ const shortcut = keyCombination.modifier
14
+ ? displayShortcutList[ keyCombination.modifier ](
15
+ keyCombination.character
16
+ )
17
+ : keyCombination.character;
18
+ const ariaLabel = keyCombination.modifier
19
+ ? shortcutAriaLabel[ keyCombination.modifier ](
20
+ keyCombination.character
21
+ )
22
+ : keyCombination.character;
23
+
24
+ return (
25
+ <kbd
26
+ className="edit-site-keyboard-shortcut-help-modal__shortcut-key-combination"
27
+ aria-label={ forceAriaLabel || ariaLabel }
28
+ >
29
+ { castArray( shortcut ).map( ( character, index ) => {
30
+ if ( character === '+' ) {
31
+ return <Fragment key={ index }>{ character }</Fragment>;
32
+ }
33
+
34
+ return (
35
+ <kbd
36
+ key={ index }
37
+ className="edit-site-keyboard-shortcut-help-modal__shortcut-key"
38
+ >
39
+ { character }
40
+ </kbd>
41
+ );
42
+ } ) }
43
+ </kbd>
44
+ );
45
+ }
46
+
47
+ export default function Shortcut( {
48
+ description,
49
+ keyCombination,
50
+ aliases = [],
51
+ ariaLabel,
52
+ } ) {
53
+ return (
54
+ <>
55
+ <div className="edit-site-keyboard-shortcut-help-modal__shortcut-description">
56
+ { description }
57
+ </div>
58
+ <div className="edit-site-keyboard-shortcut-help-modal__shortcut-term">
59
+ <KeyCombination
60
+ keyCombination={ keyCombination }
61
+ forceAriaLabel={ ariaLabel }
62
+ />
63
+ { aliases.map( ( alias, index ) => (
64
+ <KeyCombination
65
+ keyCombination={ alias }
66
+ forceAriaLabel={ ariaLabel }
67
+ key={ index }
68
+ />
69
+ ) ) }
70
+ </div>
71
+ </>
72
+ );
73
+ }
@@ -0,0 +1,66 @@
1
+ .edit-site-keyboard-shortcut-help-modal {
2
+ &__section {
3
+ margin: 0 0 2rem 0;
4
+ }
5
+
6
+ &__main-shortcuts .edit-site-keyboard-shortcut-help-modal__shortcut-list {
7
+ // Push the shortcut to be flush with top modal header.
8
+ margin-top: -$grid-unit-30 -$border-width;
9
+ }
10
+
11
+ &__section-title {
12
+ font-size: 0.9rem;
13
+ font-weight: 600;
14
+ }
15
+
16
+ &__shortcut {
17
+ display: flex;
18
+ align-items: baseline;
19
+ padding: 0.6rem 0;
20
+ border-top: 1px solid $gray-300;
21
+ margin-bottom: 0;
22
+
23
+ &:last-child {
24
+ border-bottom: 1px solid $gray-300;
25
+ }
26
+
27
+ &:empty {
28
+ display: none;
29
+ }
30
+ }
31
+
32
+ &__shortcut-term {
33
+ font-weight: 600;
34
+ margin: 0 0 0 1rem;
35
+ text-align: right;
36
+ }
37
+
38
+ &__shortcut-description {
39
+ flex: 1;
40
+ margin: 0;
41
+
42
+ // IE 11 flex item fix - ensure the item does not collapse.
43
+ flex-basis: auto;
44
+ }
45
+
46
+ &__shortcut-key-combination {
47
+ display: block;
48
+ background: none;
49
+ margin: 0;
50
+ padding: 0;
51
+
52
+ & + .edit-site-keyboard-shortcut-help-modal__shortcut-key-combination {
53
+ margin-top: 10px;
54
+ }
55
+ }
56
+
57
+ &__shortcut-key {
58
+ padding: 0.25rem 0.5rem;
59
+ border-radius: 8%;
60
+ margin: 0 0.2rem 0 0.2rem;
61
+
62
+ &:last-child {
63
+ margin: 0 0 0 0.2rem;
64
+ }
65
+ }
66
+ }