@wordpress/edit-post 7.18.0 → 7.18.1-next.5a1d1283.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/build/components/keyboard-shortcuts/index.js +4 -23
- package/build/components/keyboard-shortcuts/index.js.map +1 -1
- package/build/hooks/commands/use-common-commands.js +10 -4
- package/build/hooks/commands/use-common-commands.js.map +1 -1
- package/build/store/actions.js +53 -7
- package/build/store/actions.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/index.js +4 -23
- package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/hooks/commands/use-common-commands.js +10 -4
- package/build-module/hooks/commands/use-common-commands.js.map +1 -1
- package/build-module/store/actions.js +50 -5
- package/build-module/store/actions.js.map +1 -1
- package/package.json +32 -32
- package/src/components/keyboard-shortcuts/index.js +5 -31
- package/src/hooks/commands/use-common-commands.js +10 -1
- package/src/store/actions.js +74 -7
- package/src/store/test/actions.js +75 -0
- package/src/store/test/reducer.js +21 -9
|
@@ -33,6 +33,7 @@ export default function useCommonCommands() {
|
|
|
33
33
|
closeGeneralSidebar,
|
|
34
34
|
switchEditorMode,
|
|
35
35
|
setIsListViewOpened,
|
|
36
|
+
toggleDistractionFree,
|
|
36
37
|
} = useDispatch( editPostStore );
|
|
37
38
|
const { openModal } = useDispatch( interfaceStore );
|
|
38
39
|
const {
|
|
@@ -41,6 +42,7 @@ export default function useCommonCommands() {
|
|
|
41
42
|
isListViewOpen,
|
|
42
43
|
isPublishSidebarEnabled,
|
|
43
44
|
showBlockBreadcrumbs,
|
|
45
|
+
isDistractionFree,
|
|
44
46
|
} = useSelect( ( select ) => {
|
|
45
47
|
const { getEditorMode, isListViewOpened, isFeatureActive } =
|
|
46
48
|
select( editPostStore );
|
|
@@ -53,6 +55,10 @@ export default function useCommonCommands() {
|
|
|
53
55
|
isPublishSidebarEnabled:
|
|
54
56
|
select( editorStore ).isPublishSidebarEnabled(),
|
|
55
57
|
showBlockBreadcrumbs: isFeatureActive( 'showBlockBreadcrumbs' ),
|
|
58
|
+
isDistractionFree: select( preferencesStore ).get(
|
|
59
|
+
editPostStore.name,
|
|
60
|
+
'distractionFree'
|
|
61
|
+
),
|
|
56
62
|
};
|
|
57
63
|
}, [] );
|
|
58
64
|
const { toggle } = useDispatch( preferencesStore );
|
|
@@ -92,7 +98,7 @@ export default function useCommonCommands() {
|
|
|
92
98
|
name: 'core/toggle-distraction-free',
|
|
93
99
|
label: __( 'Toggle distraction free' ),
|
|
94
100
|
callback: ( { close } ) => {
|
|
95
|
-
|
|
101
|
+
toggleDistractionFree();
|
|
96
102
|
close();
|
|
97
103
|
},
|
|
98
104
|
} );
|
|
@@ -131,6 +137,9 @@ export default function useCommonCommands() {
|
|
|
131
137
|
label: __( 'Toggle top toolbar' ),
|
|
132
138
|
callback: ( { close } ) => {
|
|
133
139
|
toggle( 'core/edit-post', 'fixedToolbar' );
|
|
140
|
+
if ( isDistractionFree ) {
|
|
141
|
+
toggleDistractionFree();
|
|
142
|
+
}
|
|
134
143
|
close();
|
|
135
144
|
},
|
|
136
145
|
} );
|
package/src/store/actions.js
CHANGED
|
@@ -26,10 +26,17 @@ import { store as editPostStore } from '.';
|
|
|
26
26
|
*/
|
|
27
27
|
export const openGeneralSidebar =
|
|
28
28
|
( name ) =>
|
|
29
|
-
( { registry } ) =>
|
|
29
|
+
( { dispatch, registry } ) => {
|
|
30
|
+
const isDistractionFree = registry
|
|
31
|
+
.select( preferencesStore )
|
|
32
|
+
.get( 'core/edit-post', 'distractionFree' );
|
|
33
|
+
if ( isDistractionFree ) {
|
|
34
|
+
dispatch.toggleDistractionFree();
|
|
35
|
+
}
|
|
30
36
|
registry
|
|
31
37
|
.dispatch( interfaceStore )
|
|
32
38
|
.enableComplementaryArea( editPostStore.name, name );
|
|
39
|
+
};
|
|
33
40
|
|
|
34
41
|
/**
|
|
35
42
|
* Returns an action object signalling that the user closed the sidebar.
|
|
@@ -210,7 +217,7 @@ export const toggleFeature =
|
|
|
210
217
|
*/
|
|
211
218
|
export const switchEditorMode =
|
|
212
219
|
( mode ) =>
|
|
213
|
-
( { registry } ) => {
|
|
220
|
+
( { dispatch, registry } ) => {
|
|
214
221
|
registry
|
|
215
222
|
.dispatch( preferencesStore )
|
|
216
223
|
.set( 'core/edit-post', 'editorMode', mode );
|
|
@@ -220,6 +227,15 @@ export const switchEditorMode =
|
|
|
220
227
|
registry.dispatch( blockEditorStore ).clearSelectedBlock();
|
|
221
228
|
}
|
|
222
229
|
|
|
230
|
+
if (
|
|
231
|
+
mode === 'text' &&
|
|
232
|
+
registry
|
|
233
|
+
.select( preferencesStore )
|
|
234
|
+
.get( 'core/edit-post', 'distractionFree' )
|
|
235
|
+
) {
|
|
236
|
+
dispatch.toggleDistractionFree();
|
|
237
|
+
}
|
|
238
|
+
|
|
223
239
|
const message =
|
|
224
240
|
mode === 'visual'
|
|
225
241
|
? __( 'Visual editor selected' )
|
|
@@ -479,12 +495,20 @@ export function setIsInserterOpened( value ) {
|
|
|
479
495
|
* @param {boolean} isOpen A boolean representing whether the list view should be opened or closed.
|
|
480
496
|
* @return {Object} Action object.
|
|
481
497
|
*/
|
|
482
|
-
export
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
498
|
+
export const setIsListViewOpened =
|
|
499
|
+
( isOpen ) =>
|
|
500
|
+
( { dispatch, registry } ) => {
|
|
501
|
+
const isDistractionFree = registry
|
|
502
|
+
.select( preferencesStore )
|
|
503
|
+
.get( 'core/edit-post', 'distractionFree' );
|
|
504
|
+
if ( isDistractionFree && isOpen ) {
|
|
505
|
+
dispatch.toggleDistractionFree();
|
|
506
|
+
}
|
|
507
|
+
dispatch( {
|
|
508
|
+
type: 'SET_IS_LIST_VIEW_OPENED',
|
|
509
|
+
isOpen,
|
|
510
|
+
} );
|
|
486
511
|
};
|
|
487
|
-
}
|
|
488
512
|
|
|
489
513
|
/**
|
|
490
514
|
* Returns an action object used to switch to template editing.
|
|
@@ -590,3 +614,46 @@ export const initializeMetaBoxes =
|
|
|
590
614
|
type: 'META_BOXES_INITIALIZED',
|
|
591
615
|
} );
|
|
592
616
|
};
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Action that toggles Distraction free mode.
|
|
620
|
+
* Distraction free mode expects there are no sidebars, as due to the
|
|
621
|
+
* z-index values set, you can't close sidebars.
|
|
622
|
+
*/
|
|
623
|
+
export const toggleDistractionFree =
|
|
624
|
+
() =>
|
|
625
|
+
( { dispatch, registry } ) => {
|
|
626
|
+
const isDistractionFree = registry
|
|
627
|
+
.select( preferencesStore )
|
|
628
|
+
.get( 'core/edit-post', 'distractionFree' );
|
|
629
|
+
if ( ! isDistractionFree ) {
|
|
630
|
+
registry.batch( () => {
|
|
631
|
+
registry
|
|
632
|
+
.dispatch( preferencesStore )
|
|
633
|
+
.set( 'core/edit-post', 'fixedToolbar', false );
|
|
634
|
+
dispatch.setIsInserterOpened( false );
|
|
635
|
+
dispatch.setIsListViewOpened( false );
|
|
636
|
+
dispatch.closeGeneralSidebar();
|
|
637
|
+
} );
|
|
638
|
+
}
|
|
639
|
+
registry.batch( () => {
|
|
640
|
+
registry
|
|
641
|
+
.dispatch( preferencesStore )
|
|
642
|
+
.set(
|
|
643
|
+
'core/edit-post',
|
|
644
|
+
'distractionFree',
|
|
645
|
+
! isDistractionFree
|
|
646
|
+
);
|
|
647
|
+
registry
|
|
648
|
+
.dispatch( noticesStore )
|
|
649
|
+
.createInfoNotice(
|
|
650
|
+
isDistractionFree
|
|
651
|
+
? __( 'Distraction free off.' )
|
|
652
|
+
: __( 'Distraction free on.' ),
|
|
653
|
+
{
|
|
654
|
+
id: 'core/edit-post/distraction-free-mode/notice',
|
|
655
|
+
type: 'snackbar',
|
|
656
|
+
}
|
|
657
|
+
);
|
|
658
|
+
} );
|
|
659
|
+
};
|
|
@@ -53,6 +53,20 @@ describe( 'actions', () => {
|
|
|
53
53
|
).toBeNull();
|
|
54
54
|
} );
|
|
55
55
|
|
|
56
|
+
it( 'openGeneralSidebar - should turn off distraction free mode when opening a general sidebar', () => {
|
|
57
|
+
registry
|
|
58
|
+
.dispatch( preferencesStore )
|
|
59
|
+
.set( 'core/edit-post', 'distractionFree', true );
|
|
60
|
+
registry
|
|
61
|
+
.dispatch( editPostStore )
|
|
62
|
+
.openGeneralSidebar( 'edit-post/block' );
|
|
63
|
+
expect(
|
|
64
|
+
registry
|
|
65
|
+
.select( preferencesStore )
|
|
66
|
+
.get( 'core/edit-post', 'distractionFree' )
|
|
67
|
+
).toBe( false );
|
|
68
|
+
} );
|
|
69
|
+
|
|
56
70
|
it( 'toggleFeature', () => {
|
|
57
71
|
registry.dispatch( editPostStore ).toggleFeature( 'welcomeGuide' );
|
|
58
72
|
expect(
|
|
@@ -102,6 +116,17 @@ describe( 'actions', () => {
|
|
|
102
116
|
'text'
|
|
103
117
|
);
|
|
104
118
|
} );
|
|
119
|
+
it( 'should turn off distraction free mode when switching to code editor', () => {
|
|
120
|
+
registry
|
|
121
|
+
.dispatch( preferencesStore )
|
|
122
|
+
.set( 'core/edit-post', 'distractionFree', true );
|
|
123
|
+
registry.dispatch( editPostStore ).switchEditorMode( 'text' );
|
|
124
|
+
expect(
|
|
125
|
+
registry
|
|
126
|
+
.select( preferencesStore )
|
|
127
|
+
.get( 'core/edit-post', 'distractionFree' )
|
|
128
|
+
).toBe( false );
|
|
129
|
+
} );
|
|
105
130
|
} );
|
|
106
131
|
|
|
107
132
|
it( 'togglePinnedPluginItem', () => {
|
|
@@ -333,4 +358,54 @@ describe( 'actions', () => {
|
|
|
333
358
|
} );
|
|
334
359
|
} );
|
|
335
360
|
} );
|
|
361
|
+
|
|
362
|
+
describe( 'toggleDistractionFree', () => {
|
|
363
|
+
it( 'should properly update settings to prevent layout corruption when enabling distraction free mode', () => {
|
|
364
|
+
// Enable everything that shouldn't be enabled in distraction free mode.
|
|
365
|
+
registry
|
|
366
|
+
.dispatch( preferencesStore )
|
|
367
|
+
.set( 'core/edit-post', 'fixedToolbar', true );
|
|
368
|
+
registry.dispatch( editPostStore ).setIsListViewOpened( true );
|
|
369
|
+
registry
|
|
370
|
+
.dispatch( editPostStore )
|
|
371
|
+
.openGeneralSidebar( 'edit-post/block' );
|
|
372
|
+
// Initial state is falsy.
|
|
373
|
+
registry.dispatch( editPostStore ).toggleDistractionFree();
|
|
374
|
+
expect(
|
|
375
|
+
registry
|
|
376
|
+
.select( preferencesStore )
|
|
377
|
+
.get( 'core/edit-post', 'fixedToolbar' )
|
|
378
|
+
).toBe( false );
|
|
379
|
+
expect( registry.select( editPostStore ).isListViewOpened() ).toBe(
|
|
380
|
+
false
|
|
381
|
+
);
|
|
382
|
+
expect( registry.select( editPostStore ).isInserterOpened() ).toBe(
|
|
383
|
+
false
|
|
384
|
+
);
|
|
385
|
+
expect(
|
|
386
|
+
registry
|
|
387
|
+
.select( interfaceStore )
|
|
388
|
+
.getActiveComplementaryArea( editPostStore.name )
|
|
389
|
+
).toBeNull();
|
|
390
|
+
expect(
|
|
391
|
+
registry
|
|
392
|
+
.select( preferencesStore )
|
|
393
|
+
.get( 'core/edit-post', 'distractionFree' )
|
|
394
|
+
).toBe( true );
|
|
395
|
+
} );
|
|
396
|
+
} );
|
|
397
|
+
|
|
398
|
+
describe( 'setIsListViewOpened', () => {
|
|
399
|
+
it( 'should turn off distraction free mode when opening the list view', () => {
|
|
400
|
+
registry
|
|
401
|
+
.dispatch( preferencesStore )
|
|
402
|
+
.set( 'core/edit-post', 'distractionFree', true );
|
|
403
|
+
registry.dispatch( editPostStore ).setIsListViewOpened( true );
|
|
404
|
+
expect(
|
|
405
|
+
registry
|
|
406
|
+
.select( preferencesStore )
|
|
407
|
+
.get( 'core/edit-post', 'distractionFree' )
|
|
408
|
+
).toBe( false );
|
|
409
|
+
} );
|
|
410
|
+
} );
|
|
336
411
|
} );
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
listViewPanel,
|
|
15
15
|
} from '../reducer';
|
|
16
16
|
|
|
17
|
-
import { setIsInserterOpened
|
|
17
|
+
import { setIsInserterOpened } from '../actions';
|
|
18
18
|
|
|
19
19
|
describe( 'state', () => {
|
|
20
20
|
describe( 'isSavingMetaBoxes', () => {
|
|
@@ -135,13 +135,19 @@ describe( 'state', () => {
|
|
|
135
135
|
|
|
136
136
|
it( 'should close the inserter when opening the list view panel', () => {
|
|
137
137
|
expect(
|
|
138
|
-
blockInserterPanel( true,
|
|
138
|
+
blockInserterPanel( true, {
|
|
139
|
+
type: 'SET_IS_LIST_VIEW_OPENED',
|
|
140
|
+
isOpen: true,
|
|
141
|
+
} )
|
|
139
142
|
).toBe( false );
|
|
140
143
|
} );
|
|
141
144
|
|
|
142
145
|
it( 'should not change the state when closing the list view panel', () => {
|
|
143
146
|
expect(
|
|
144
|
-
blockInserterPanel( true,
|
|
147
|
+
blockInserterPanel( true, {
|
|
148
|
+
type: 'SET_IS_LIST_VIEW_OPENED',
|
|
149
|
+
isOpen: false,
|
|
150
|
+
} )
|
|
145
151
|
).toBe( true );
|
|
146
152
|
} );
|
|
147
153
|
} );
|
|
@@ -156,12 +162,18 @@ describe( 'state', () => {
|
|
|
156
162
|
} );
|
|
157
163
|
|
|
158
164
|
it( 'should set the open state of the list view panel', () => {
|
|
159
|
-
expect(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
);
|
|
165
|
+
expect(
|
|
166
|
+
listViewPanel( false, {
|
|
167
|
+
type: 'SET_IS_LIST_VIEW_OPENED',
|
|
168
|
+
isOpen: true,
|
|
169
|
+
} )
|
|
170
|
+
).toBe( true );
|
|
171
|
+
expect(
|
|
172
|
+
listViewPanel( true, {
|
|
173
|
+
type: 'SET_IS_LIST_VIEW_OPENED',
|
|
174
|
+
isOpen: false,
|
|
175
|
+
} )
|
|
176
|
+
).toBe( false );
|
|
165
177
|
} );
|
|
166
178
|
|
|
167
179
|
it( 'should close the list view when opening the inserter panel', () => {
|