@wordpress/edit-post 7.13.0 → 7.14.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.
- package/CHANGELOG.md +2 -0
- package/build/components/header/header-toolbar/index.js +7 -1
- package/build/components/header/header-toolbar/index.js.map +1 -1
- package/build/components/header/index.js +25 -24
- package/build/components/header/index.js.map +1 -1
- package/build/components/header/preferences-menu-item/index.js +5 -3
- package/build/components/header/preferences-menu-item/index.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/index.js +8 -6
- package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build/components/keyboard-shortcuts/index.js +0 -2
- package/build/components/keyboard-shortcuts/index.js.map +1 -1
- package/build/components/layout/index.js +11 -1
- package/build/components/layout/index.js.map +1 -1
- package/build/components/preferences-modal/index.js +5 -3
- package/build/components/preferences-modal/index.js.map +1 -1
- package/build/components/sidebar/post-status/index.js +2 -1
- package/build/components/sidebar/post-status/index.js.map +1 -1
- package/build/components/sidebar/post-trash/index.js +1 -5
- package/build/components/sidebar/post-trash/index.js.map +1 -1
- package/build/editor.js +3 -0
- package/build/editor.js.map +1 -1
- package/build/hooks/commands/use-common-commands.js +176 -0
- package/build/hooks/commands/use-common-commands.js.map +1 -0
- package/build/plugins/keyboard-shortcuts-help-menu-item/index.js +5 -3
- package/build/plugins/keyboard-shortcuts-help-menu-item/index.js.map +1 -1
- package/build/store/actions.js +31 -15
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +0 -23
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +11 -7
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/header/header-toolbar/index.js +6 -1
- package/build-module/components/header/header-toolbar/index.js.map +1 -1
- package/build-module/components/header/index.js +24 -24
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/header/preferences-menu-item/index.js +4 -3
- package/build-module/components/header/preferences-menu-item/index.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.js +5 -5
- package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/index.js +0 -2
- package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/layout/index.js +11 -2
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/preferences-modal/index.js +4 -4
- package/build-module/components/preferences-modal/index.js.map +1 -1
- package/build-module/components/sidebar/post-status/index.js +2 -1
- package/build-module/components/sidebar/post-status/index.js.map +1 -1
- package/build-module/components/sidebar/post-trash/index.js +1 -4
- package/build-module/components/sidebar/post-trash/index.js.map +1 -1
- package/build-module/editor.js +2 -0
- package/build-module/editor.js.map +1 -1
- package/build-module/hooks/commands/use-common-commands.js +160 -0
- package/build-module/hooks/commands/use-common-commands.js.map +1 -0
- package/build-module/plugins/keyboard-shortcuts-help-menu-item/index.js +4 -3
- package/build-module/plugins/keyboard-shortcuts-help-menu-item/index.js.map +1 -1
- package/build-module/store/actions.js +24 -11
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +0 -21
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +9 -3
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +1 -2
- package/build-style/style.css +1 -2
- package/package.json +32 -32
- package/src/components/block-manager/style.scss +1 -1
- package/src/components/header/header-toolbar/index.js +4 -1
- package/src/components/header/index.js +10 -10
- package/src/components/header/preferences-menu-item/index.js +4 -3
- package/src/components/keyboard-shortcut-help-modal/index.js +10 -5
- package/src/components/keyboard-shortcuts/index.js +0 -2
- package/src/components/layout/index.js +14 -1
- package/src/components/preferences-modal/index.js +6 -4
- package/src/components/preferences-modal/test/__snapshots__/index.js.snap +1 -1
- package/src/components/sidebar/post-status/index.js +1 -0
- package/src/components/sidebar/post-trash/index.js +1 -4
- package/src/components/start-page-options/style.scss +0 -3
- package/src/editor.js +2 -0
- package/src/hooks/commands/use-common-commands.js +155 -0
- package/src/plugins/keyboard-shortcuts-help-menu-item/index.js +4 -3
- package/src/store/actions.js +22 -9
- package/src/store/reducer.js +0 -20
- package/src/store/selectors.js +11 -3
- package/src/store/test/reducer.js +0 -25
- package/src/store/test/selectors.js +0 -27
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
5
|
+
import { __, isRTL } from '@wordpress/i18n';
|
|
6
|
+
import {
|
|
7
|
+
code,
|
|
8
|
+
cog,
|
|
9
|
+
drawerLeft,
|
|
10
|
+
drawerRight,
|
|
11
|
+
blockDefault,
|
|
12
|
+
keyboardClose,
|
|
13
|
+
desktop,
|
|
14
|
+
listView,
|
|
15
|
+
} from '@wordpress/icons';
|
|
16
|
+
import { useCommand } from '@wordpress/commands';
|
|
17
|
+
import { store as preferencesStore } from '@wordpress/preferences';
|
|
18
|
+
import { store as interfaceStore } from '@wordpress/interface';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Internal dependencies
|
|
22
|
+
*/
|
|
23
|
+
import { KEYBOARD_SHORTCUT_HELP_MODAL_NAME } from '../../components/keyboard-shortcut-help-modal';
|
|
24
|
+
import { PREFERENCES_MODAL_NAME } from '../../components/preferences-modal';
|
|
25
|
+
import { store as editPostStore } from '../../store';
|
|
26
|
+
|
|
27
|
+
export default function useCommonCommands() {
|
|
28
|
+
const {
|
|
29
|
+
openGeneralSidebar,
|
|
30
|
+
closeGeneralSidebar,
|
|
31
|
+
switchEditorMode,
|
|
32
|
+
setIsListViewOpened,
|
|
33
|
+
} = useDispatch( editPostStore );
|
|
34
|
+
const { openModal } = useDispatch( interfaceStore );
|
|
35
|
+
const { editorMode, activeSidebar, isListViewOpen } = useSelect(
|
|
36
|
+
( select ) => {
|
|
37
|
+
const { getEditorMode, isListViewOpened } = select( editPostStore );
|
|
38
|
+
return {
|
|
39
|
+
activeSidebar: select(
|
|
40
|
+
interfaceStore
|
|
41
|
+
).getActiveComplementaryArea( editPostStore.name ),
|
|
42
|
+
editorMode: getEditorMode(),
|
|
43
|
+
isListViewOpen: isListViewOpened(),
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
[]
|
|
47
|
+
);
|
|
48
|
+
const { toggle } = useDispatch( preferencesStore );
|
|
49
|
+
|
|
50
|
+
useCommand( {
|
|
51
|
+
name: 'core/open-settings-sidebar',
|
|
52
|
+
label: __( 'Toggle settings sidebar' ),
|
|
53
|
+
icon: isRTL() ? drawerLeft : drawerRight,
|
|
54
|
+
callback: ( { close } ) => {
|
|
55
|
+
close();
|
|
56
|
+
if ( activeSidebar === 'edit-post/document' ) {
|
|
57
|
+
closeGeneralSidebar();
|
|
58
|
+
} else {
|
|
59
|
+
openGeneralSidebar( 'edit-post/document' );
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
} );
|
|
63
|
+
|
|
64
|
+
useCommand( {
|
|
65
|
+
name: 'core/open-block-inspector',
|
|
66
|
+
label: __( 'Toggle block inspector' ),
|
|
67
|
+
icon: blockDefault,
|
|
68
|
+
callback: ( { close } ) => {
|
|
69
|
+
close();
|
|
70
|
+
if ( activeSidebar === 'edit-post/block' ) {
|
|
71
|
+
closeGeneralSidebar();
|
|
72
|
+
} else {
|
|
73
|
+
openGeneralSidebar( 'edit-post/block' );
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
} );
|
|
77
|
+
|
|
78
|
+
useCommand( {
|
|
79
|
+
name: 'core/toggle-distraction-free',
|
|
80
|
+
label: __( 'Toggle distraction free' ),
|
|
81
|
+
icon: cog,
|
|
82
|
+
callback: ( { close } ) => {
|
|
83
|
+
toggle( 'core/edit-post', 'distractionFree' );
|
|
84
|
+
close();
|
|
85
|
+
},
|
|
86
|
+
} );
|
|
87
|
+
|
|
88
|
+
useCommand( {
|
|
89
|
+
name: 'core/toggle-spotlight-mode',
|
|
90
|
+
label: __( 'Toggle spotlight mode' ),
|
|
91
|
+
icon: cog,
|
|
92
|
+
callback: ( { close } ) => {
|
|
93
|
+
toggle( 'core/edit-post', 'focusMode' );
|
|
94
|
+
close();
|
|
95
|
+
},
|
|
96
|
+
} );
|
|
97
|
+
|
|
98
|
+
useCommand( {
|
|
99
|
+
name: 'core/toggle-fullscreen-mode',
|
|
100
|
+
label: __( 'Toggle fullscreen mode' ),
|
|
101
|
+
icon: desktop,
|
|
102
|
+
callback: ( { close } ) => {
|
|
103
|
+
toggle( 'core/edit-post', 'fullscreenMode' );
|
|
104
|
+
close();
|
|
105
|
+
},
|
|
106
|
+
} );
|
|
107
|
+
|
|
108
|
+
useCommand( {
|
|
109
|
+
name: 'core/toggle-list-view',
|
|
110
|
+
label: __( 'Toggle list view' ),
|
|
111
|
+
icon: listView,
|
|
112
|
+
callback: ( { close } ) => {
|
|
113
|
+
setIsListViewOpened( ! isListViewOpen );
|
|
114
|
+
close();
|
|
115
|
+
},
|
|
116
|
+
} );
|
|
117
|
+
|
|
118
|
+
useCommand( {
|
|
119
|
+
name: 'core/toggle-top-toolbar',
|
|
120
|
+
label: __( 'Toggle top toolbar' ),
|
|
121
|
+
icon: cog,
|
|
122
|
+
callback: ( { close } ) => {
|
|
123
|
+
toggle( 'core/edit-post', 'fixedToolbar' );
|
|
124
|
+
close();
|
|
125
|
+
},
|
|
126
|
+
} );
|
|
127
|
+
|
|
128
|
+
useCommand( {
|
|
129
|
+
name: 'core/toggle-code-editor',
|
|
130
|
+
label: __( 'Toggle code editor' ),
|
|
131
|
+
icon: code,
|
|
132
|
+
callback: ( { close } ) => {
|
|
133
|
+
switchEditorMode( editorMode === 'visual' ? 'text' : 'visual' );
|
|
134
|
+
close();
|
|
135
|
+
},
|
|
136
|
+
} );
|
|
137
|
+
|
|
138
|
+
useCommand( {
|
|
139
|
+
name: 'core/open-preferences',
|
|
140
|
+
label: __( 'Open editor preferences' ),
|
|
141
|
+
icon: cog,
|
|
142
|
+
callback: () => {
|
|
143
|
+
openModal( PREFERENCES_MODAL_NAME );
|
|
144
|
+
},
|
|
145
|
+
} );
|
|
146
|
+
|
|
147
|
+
useCommand( {
|
|
148
|
+
name: 'core/open-shortcut-help',
|
|
149
|
+
label: __( 'Open keyboard shortcuts' ),
|
|
150
|
+
icon: keyboardClose,
|
|
151
|
+
callback: () => {
|
|
152
|
+
openModal( KEYBOARD_SHORTCUT_HELP_MODAL_NAME );
|
|
153
|
+
},
|
|
154
|
+
} );
|
|
155
|
+
}
|
|
@@ -5,17 +5,18 @@ import { MenuItem } from '@wordpress/components';
|
|
|
5
5
|
import { withDispatch } from '@wordpress/data';
|
|
6
6
|
import { __ } from '@wordpress/i18n';
|
|
7
7
|
import { displayShortcut } from '@wordpress/keycodes';
|
|
8
|
+
import { store as interfaceStore } from '@wordpress/interface';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Internal dependencies
|
|
11
12
|
*/
|
|
12
|
-
import {
|
|
13
|
+
import { KEYBOARD_SHORTCUT_HELP_MODAL_NAME } from '../../components/keyboard-shortcut-help-modal';
|
|
13
14
|
|
|
14
15
|
export function KeyboardShortcutsHelpMenuItem( { openModal } ) {
|
|
15
16
|
return (
|
|
16
17
|
<MenuItem
|
|
17
18
|
onClick={ () => {
|
|
18
|
-
openModal(
|
|
19
|
+
openModal( KEYBOARD_SHORTCUT_HELP_MODAL_NAME );
|
|
19
20
|
} }
|
|
20
21
|
shortcut={ displayShortcut.access( 'h' ) }
|
|
21
22
|
>
|
|
@@ -25,7 +26,7 @@ export function KeyboardShortcutsHelpMenuItem( { openModal } ) {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
export default withDispatch( ( dispatch ) => {
|
|
28
|
-
const { openModal } = dispatch(
|
|
29
|
+
const { openModal } = dispatch( interfaceStore );
|
|
29
30
|
|
|
30
31
|
return {
|
|
31
32
|
openModal,
|
package/src/store/actions.js
CHANGED
|
@@ -10,6 +10,7 @@ import { store as noticesStore } from '@wordpress/notices';
|
|
|
10
10
|
import { store as coreStore } from '@wordpress/core-data';
|
|
11
11
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
12
12
|
import { store as editorStore } from '@wordpress/editor';
|
|
13
|
+
import deprecated from '@wordpress/deprecated';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Internal dependencies
|
|
@@ -42,27 +43,39 @@ export const closeGeneralSidebar =
|
|
|
42
43
|
/**
|
|
43
44
|
* Returns an action object used in signalling that the user opened a modal.
|
|
44
45
|
*
|
|
46
|
+
* @deprecated since WP 6.3 use `core/interface` store's action with the same name instead.
|
|
47
|
+
*
|
|
48
|
+
*
|
|
45
49
|
* @param {string} name A string that uniquely identifies the modal.
|
|
46
50
|
*
|
|
47
51
|
* @return {Object} Action object.
|
|
48
52
|
*/
|
|
49
|
-
export
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
name,
|
|
53
|
+
export const openModal =
|
|
54
|
+
( name ) =>
|
|
55
|
+
( { registry } ) => {
|
|
56
|
+
deprecated( "select( 'core/edit-post' ).openModal( name )", {
|
|
57
|
+
since: '6.3',
|
|
58
|
+
alternative: "select( 'core/interface').openModal( name )",
|
|
59
|
+
} );
|
|
60
|
+
return registry.dispatch( interfaceStore ).openModal( name );
|
|
53
61
|
};
|
|
54
|
-
}
|
|
55
62
|
|
|
56
63
|
/**
|
|
57
64
|
* Returns an action object signalling that the user closed a modal.
|
|
58
65
|
*
|
|
66
|
+
* @deprecated since WP 6.3 use `core/interface` store's action with the same name instead.
|
|
67
|
+
*
|
|
59
68
|
* @return {Object} Action object.
|
|
60
69
|
*/
|
|
61
|
-
export
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
export const closeModal =
|
|
71
|
+
() =>
|
|
72
|
+
( { registry } ) => {
|
|
73
|
+
deprecated( "select( 'core/edit-post' ).closeModal()", {
|
|
74
|
+
since: '6.3',
|
|
75
|
+
alternative: "select( 'core/interface').closeModal()",
|
|
76
|
+
} );
|
|
77
|
+
return registry.dispatch( interfaceStore ).closeModal();
|
|
64
78
|
};
|
|
65
|
-
}
|
|
66
79
|
|
|
67
80
|
/**
|
|
68
81
|
* Returns an action object used in signalling that the user opened the publish
|
package/src/store/reducer.js
CHANGED
|
@@ -22,25 +22,6 @@ export function removedPanels( state = [], action ) {
|
|
|
22
22
|
return state;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
/**
|
|
26
|
-
* Reducer for storing the name of the open modal, or null if no modal is open.
|
|
27
|
-
*
|
|
28
|
-
* @param {Object} state Previous state.
|
|
29
|
-
* @param {Object} action Action object containing the `name` of the modal
|
|
30
|
-
*
|
|
31
|
-
* @return {Object} Updated state
|
|
32
|
-
*/
|
|
33
|
-
export function activeModal( state = null, action ) {
|
|
34
|
-
switch ( action.type ) {
|
|
35
|
-
case 'OPEN_MODAL':
|
|
36
|
-
return action.name;
|
|
37
|
-
case 'CLOSE_MODAL':
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return state;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
25
|
export function publishSidebarActive( state = false, action ) {
|
|
45
26
|
switch ( action.type ) {
|
|
46
27
|
case 'OPEN_PUBLISH_SIDEBAR':
|
|
@@ -209,7 +190,6 @@ const metaBoxes = combineReducers( {
|
|
|
209
190
|
} );
|
|
210
191
|
|
|
211
192
|
export default combineReducers( {
|
|
212
|
-
activeModal,
|
|
213
193
|
metaBoxes,
|
|
214
194
|
publishSidebarActive,
|
|
215
195
|
removedPanels,
|
package/src/store/selectors.js
CHANGED
|
@@ -298,14 +298,22 @@ export const isEditorPanelOpened = createRegistrySelector(
|
|
|
298
298
|
/**
|
|
299
299
|
* Returns true if a modal is active, or false otherwise.
|
|
300
300
|
*
|
|
301
|
+
* @deprecated since WP 6.3 use `core/interface` store's selector with the same name instead.
|
|
302
|
+
*
|
|
301
303
|
* @param {Object} state Global application state.
|
|
302
304
|
* @param {string} modalName A string that uniquely identifies the modal.
|
|
303
305
|
*
|
|
304
306
|
* @return {boolean} Whether the modal is active.
|
|
305
307
|
*/
|
|
306
|
-
export
|
|
307
|
-
|
|
308
|
-
|
|
308
|
+
export const isModalActive = createRegistrySelector(
|
|
309
|
+
( select ) => ( state, modalName ) => {
|
|
310
|
+
deprecated( `select( 'core/edit-post' ).isModalActive`, {
|
|
311
|
+
since: '6.3',
|
|
312
|
+
alternative: `select( 'core/interface' ).isModalActive`,
|
|
313
|
+
} );
|
|
314
|
+
return !! select( interfaceStore ).isModalActive( modalName );
|
|
315
|
+
}
|
|
316
|
+
);
|
|
309
317
|
|
|
310
318
|
/**
|
|
311
319
|
* Returns whether the given feature is enabled or not.
|
|
@@ -7,7 +7,6 @@ import deepFreeze from 'deep-freeze';
|
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
9
|
import {
|
|
10
|
-
activeModal,
|
|
11
10
|
isSavingMetaBoxes,
|
|
12
11
|
metaBoxLocations,
|
|
13
12
|
removedPanels,
|
|
@@ -18,30 +17,6 @@ import {
|
|
|
18
17
|
import { setIsInserterOpened, setIsListViewOpened } from '../actions';
|
|
19
18
|
|
|
20
19
|
describe( 'state', () => {
|
|
21
|
-
describe( 'activeModal', () => {
|
|
22
|
-
it( 'should default to null', () => {
|
|
23
|
-
const state = activeModal( undefined, {} );
|
|
24
|
-
expect( state ).toBeNull();
|
|
25
|
-
} );
|
|
26
|
-
|
|
27
|
-
it( 'should set the activeModal to the provided name', () => {
|
|
28
|
-
const state = activeModal( null, {
|
|
29
|
-
type: 'OPEN_MODAL',
|
|
30
|
-
name: 'test-modal',
|
|
31
|
-
} );
|
|
32
|
-
|
|
33
|
-
expect( state ).toEqual( 'test-modal' );
|
|
34
|
-
} );
|
|
35
|
-
|
|
36
|
-
it( 'should set the activeModal to null', () => {
|
|
37
|
-
const state = activeModal( 'test-modal', {
|
|
38
|
-
type: 'CLOSE_MODAL',
|
|
39
|
-
} );
|
|
40
|
-
|
|
41
|
-
expect( state ).toBeNull();
|
|
42
|
-
} );
|
|
43
|
-
} );
|
|
44
|
-
|
|
45
20
|
describe( 'isSavingMetaBoxes', () => {
|
|
46
21
|
it( 'should return default state', () => {
|
|
47
22
|
const actual = isSavingMetaBoxes( undefined, {} );
|
|
@@ -7,7 +7,6 @@ import deepFreeze from 'deep-freeze';
|
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
9
|
import {
|
|
10
|
-
isModalActive,
|
|
11
10
|
hasMetaBoxes,
|
|
12
11
|
isSavingMetaBoxes,
|
|
13
12
|
getActiveMetaBoxLocations,
|
|
@@ -18,32 +17,6 @@ import {
|
|
|
18
17
|
} from '../selectors';
|
|
19
18
|
|
|
20
19
|
describe( 'selectors', () => {
|
|
21
|
-
describe( 'isModalActive', () => {
|
|
22
|
-
it( 'returns true if the provided name matches the value in the preferences activeModal property', () => {
|
|
23
|
-
const state = {
|
|
24
|
-
activeModal: 'test-modal',
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
expect( isModalActive( state, 'test-modal' ) ).toBe( true );
|
|
28
|
-
} );
|
|
29
|
-
|
|
30
|
-
it( 'returns false if the provided name does not match the preferences activeModal property', () => {
|
|
31
|
-
const state = {
|
|
32
|
-
activeModal: 'something-else',
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
expect( isModalActive( state, 'test-modal' ) ).toBe( false );
|
|
36
|
-
} );
|
|
37
|
-
|
|
38
|
-
it( 'returns false if the preferences activeModal property is null', () => {
|
|
39
|
-
const state = {
|
|
40
|
-
activeModal: null,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
expect( isModalActive( state, 'test-modal' ) ).toBe( false );
|
|
44
|
-
} );
|
|
45
|
-
} );
|
|
46
|
-
|
|
47
20
|
describe( 'isEditorPanelRemoved', () => {
|
|
48
21
|
it( 'should return false by default', () => {
|
|
49
22
|
const state = deepFreeze( {
|