@wordpress/edit-post 7.18.0 → 7.19.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/index.js +6 -0
- package/build/components/header/index.js.map +1 -1
- package/build/components/keyboard-shortcuts/index.js +4 -23
- package/build/components/keyboard-shortcuts/index.js.map +1 -1
- package/build/components/layout/index.js +9 -3
- package/build/components/layout/index.js.map +1 -1
- package/build/components/start-page-options/index.js +2 -3
- package/build/components/start-page-options/index.js.map +1 -1
- package/build/components/visual-editor/index.js +34 -44
- package/build/components/visual-editor/index.js.map +1 -1
- package/build/editor.js +2 -3
- package/build/editor.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/header/index.js +6 -0
- package/build-module/components/header/index.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/components/layout/index.js +9 -3
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/start-page-options/index.js +2 -3
- package/build-module/components/start-page-options/index.js.map +1 -1
- package/build-module/components/visual-editor/index.js +35 -45
- package/build-module/components/visual-editor/index.js.map +1 -1
- package/build-module/editor.js +2 -3
- package/build-module/editor.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/build-style/style-rtl.css +94 -8
- package/build-style/style.css +94 -8
- package/package.json +32 -32
- package/src/components/header/index.js +2 -0
- package/src/components/keyboard-shortcut-help-modal/test/index.js +4 -5
- package/src/components/keyboard-shortcuts/index.js +5 -31
- package/src/components/layout/index.js +9 -2
- package/src/components/preferences-modal/test/index.js +35 -8
- package/src/components/start-page-options/index.js +4 -5
- package/src/components/visual-editor/index.js +49 -55
- package/src/components/visual-editor/style.scss +89 -0
- package/src/editor.js +17 -20
- 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
- package/src/style.scss +0 -9
- package/src/components/preferences-modal/test/__snapshots__/index.js.snap +0 -942
|
@@ -8,19 +8,13 @@ import classnames from 'classnames';
|
|
|
8
8
|
*/
|
|
9
9
|
import { PostTitle, store as editorStore } from '@wordpress/editor';
|
|
10
10
|
import {
|
|
11
|
-
WritingFlow,
|
|
12
11
|
BlockList,
|
|
13
12
|
BlockTools,
|
|
14
13
|
store as blockEditorStore,
|
|
15
|
-
__unstableUseBlockSelectionClearer as useBlockSelectionClearer,
|
|
16
14
|
__unstableUseTypewriter as useTypewriter,
|
|
17
|
-
__unstableUseClipboardHandler as useClipboardHandler,
|
|
18
15
|
__unstableUseTypingObserver as useTypingObserver,
|
|
19
16
|
__experimentalUseResizeCanvas as useResizeCanvas,
|
|
20
|
-
__unstableEditorStyles as EditorStyles,
|
|
21
17
|
useSetting,
|
|
22
|
-
__unstableUseMouseMoveTypingReset as useMouseMoveTypingReset,
|
|
23
|
-
__unstableIframe as Iframe,
|
|
24
18
|
__experimentalRecursionProvider as RecursionProvider,
|
|
25
19
|
privateApis as blockEditorPrivateApis,
|
|
26
20
|
} from '@wordpress/block-editor';
|
|
@@ -37,44 +31,15 @@ import { store as coreStore } from '@wordpress/core-data';
|
|
|
37
31
|
import { store as editPostStore } from '../../store';
|
|
38
32
|
import { unlock } from '../../lock-unlock';
|
|
39
33
|
|
|
40
|
-
const {
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
const {
|
|
35
|
+
LayoutStyle,
|
|
36
|
+
useLayoutClasses,
|
|
37
|
+
useLayoutStyles,
|
|
38
|
+
ExperimentalBlockCanvas: BlockCanvas,
|
|
39
|
+
} = unlock( blockEditorPrivateApis );
|
|
43
40
|
|
|
44
41
|
const isGutenbergPlugin = process.env.IS_GUTENBERG_PLUGIN ? true : false;
|
|
45
42
|
|
|
46
|
-
function MaybeIframe( { children, contentRef, shouldIframe, styles, style } ) {
|
|
47
|
-
const ref = useMouseMoveTypingReset();
|
|
48
|
-
|
|
49
|
-
if ( ! shouldIframe ) {
|
|
50
|
-
return (
|
|
51
|
-
<>
|
|
52
|
-
<EditorStyles styles={ styles } />
|
|
53
|
-
<WritingFlow
|
|
54
|
-
ref={ contentRef }
|
|
55
|
-
className="editor-styles-wrapper"
|
|
56
|
-
style={ { flex: '1', ...style } }
|
|
57
|
-
tabIndex={ -1 }
|
|
58
|
-
>
|
|
59
|
-
{ children }
|
|
60
|
-
</WritingFlow>
|
|
61
|
-
</>
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return (
|
|
66
|
-
<Iframe
|
|
67
|
-
ref={ ref }
|
|
68
|
-
contentRef={ contentRef }
|
|
69
|
-
style={ { width: '100%', height: '100%', display: 'block' } }
|
|
70
|
-
name="editor-canvas"
|
|
71
|
-
>
|
|
72
|
-
<EditorStyles styles={ styles } />
|
|
73
|
-
{ children }
|
|
74
|
-
</Iframe>
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
43
|
/**
|
|
79
44
|
* Given an array of nested blocks, find the first Post Content
|
|
80
45
|
* block inside it, recursing through any nesting levels,
|
|
@@ -101,6 +66,15 @@ function getPostContentAttributes( blocks ) {
|
|
|
101
66
|
}
|
|
102
67
|
}
|
|
103
68
|
|
|
69
|
+
function checkForPostContentAtRootLevel( blocks ) {
|
|
70
|
+
for ( let i = 0; i < blocks.length; i++ ) {
|
|
71
|
+
if ( blocks[ i ].name === 'core/post-content' ) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
104
78
|
export default function VisualEditor( { styles } ) {
|
|
105
79
|
const {
|
|
106
80
|
deviceType,
|
|
@@ -123,9 +97,10 @@ export default function VisualEditor( { styles } ) {
|
|
|
123
97
|
select( editorStore );
|
|
124
98
|
const { getBlockTypes } = select( blocksStore );
|
|
125
99
|
const _isTemplateMode = isEditingTemplate();
|
|
100
|
+
const postTypeSlug = getCurrentPostType();
|
|
126
101
|
let _wrapperBlockName;
|
|
127
102
|
|
|
128
|
-
if (
|
|
103
|
+
if ( postTypeSlug === 'wp_block' ) {
|
|
129
104
|
_wrapperBlockName = 'core/block';
|
|
130
105
|
} else if ( ! _isTemplateMode ) {
|
|
131
106
|
_wrapperBlockName = 'core/post-content';
|
|
@@ -133,6 +108,7 @@ export default function VisualEditor( { styles } ) {
|
|
|
133
108
|
|
|
134
109
|
const editorSettings = getEditorSettings();
|
|
135
110
|
const supportsTemplateMode = editorSettings.supportsTemplateMode;
|
|
111
|
+
const postType = select( coreStore ).getPostType( postTypeSlug );
|
|
136
112
|
const canEditTemplate = select( coreStore ).canUser(
|
|
137
113
|
'create',
|
|
138
114
|
'templates'
|
|
@@ -146,7 +122,7 @@ export default function VisualEditor( { styles } ) {
|
|
|
146
122
|
// Post template fetch returns a 404 on classic themes, which
|
|
147
123
|
// messes with e2e tests, so check it's a block theme first.
|
|
148
124
|
editedPostTemplate:
|
|
149
|
-
supportsTemplateMode && canEditTemplate
|
|
125
|
+
postType?.viewable && supportsTemplateMode && canEditTemplate
|
|
150
126
|
? getEditedPostTemplate()
|
|
151
127
|
: undefined,
|
|
152
128
|
wrapperBlockName: _wrapperBlockName,
|
|
@@ -214,14 +190,7 @@ export default function VisualEditor( { styles } ) {
|
|
|
214
190
|
}
|
|
215
191
|
|
|
216
192
|
const ref = useRef();
|
|
217
|
-
const contentRef = useMergeRefs( [
|
|
218
|
-
ref,
|
|
219
|
-
useClipboardHandler(),
|
|
220
|
-
useTypewriter(),
|
|
221
|
-
useBlockSelectionClearer(),
|
|
222
|
-
] );
|
|
223
|
-
|
|
224
|
-
const blockSelectionClearerRef = useBlockSelectionClearer();
|
|
193
|
+
const contentRef = useMergeRefs( [ ref, useTypewriter() ] );
|
|
225
194
|
|
|
226
195
|
// fallbackLayout is used if there is no Post Content,
|
|
227
196
|
// and for Post Title.
|
|
@@ -261,6 +230,26 @@ export default function VisualEditor( { styles } ) {
|
|
|
261
230
|
postContentAttributes,
|
|
262
231
|
] );
|
|
263
232
|
|
|
233
|
+
const hasPostContentAtRootLevel = useMemo( () => {
|
|
234
|
+
if ( ! editedPostTemplate?.content && ! editedPostTemplate?.blocks ) {
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
// When in template editing mode, we can access the blocks directly.
|
|
238
|
+
if ( editedPostTemplate?.blocks ) {
|
|
239
|
+
return checkForPostContentAtRootLevel( editedPostTemplate?.blocks );
|
|
240
|
+
}
|
|
241
|
+
// If there are no blocks, we have to parse the content string.
|
|
242
|
+
// Best double-check it's a string otherwise the parse function gets unhappy.
|
|
243
|
+
const parseableContent =
|
|
244
|
+
typeof editedPostTemplate?.content === 'string'
|
|
245
|
+
? editedPostTemplate?.content
|
|
246
|
+
: '';
|
|
247
|
+
|
|
248
|
+
return (
|
|
249
|
+
checkForPostContentAtRootLevel( parse( parseableContent ) ) || false
|
|
250
|
+
);
|
|
251
|
+
}, [ editedPostTemplate?.content, editedPostTemplate?.blocks ] );
|
|
252
|
+
|
|
264
253
|
const { layout = {}, align = '' } = newestPostContentAttributes || {};
|
|
265
254
|
|
|
266
255
|
const postContentLayoutClasses = useLayoutClasses(
|
|
@@ -305,6 +294,11 @@ export default function VisualEditor( { styles } ) {
|
|
|
305
294
|
? postContentLayout
|
|
306
295
|
: fallbackLayout;
|
|
307
296
|
|
|
297
|
+
const postEditorLayout =
|
|
298
|
+
blockListLayout?.type === 'default' && ! hasPostContentAtRootLevel
|
|
299
|
+
? fallbackLayout
|
|
300
|
+
: blockListLayout;
|
|
301
|
+
|
|
308
302
|
const observeTypingRef = useTypingObserver();
|
|
309
303
|
const titleRef = useRef();
|
|
310
304
|
useEffect( () => {
|
|
@@ -355,17 +349,17 @@ export default function VisualEditor( { styles } ) {
|
|
|
355
349
|
animate={ {
|
|
356
350
|
padding: isTemplateMode ? '48px 48px 0' : 0,
|
|
357
351
|
} }
|
|
358
|
-
ref={ blockSelectionClearerRef }
|
|
359
352
|
>
|
|
360
353
|
<motion.div
|
|
361
354
|
animate={ animatedStyles }
|
|
362
355
|
initial={ desktopCanvasStyles }
|
|
363
356
|
className={ previewMode }
|
|
364
357
|
>
|
|
365
|
-
<
|
|
358
|
+
<BlockCanvas
|
|
366
359
|
shouldIframe={ isToBeIframed }
|
|
367
360
|
contentRef={ contentRef }
|
|
368
361
|
styles={ styles }
|
|
362
|
+
height="100%"
|
|
369
363
|
>
|
|
370
364
|
{ themeSupportsLayout &&
|
|
371
365
|
! themeHasDisabledLayoutStyles &&
|
|
@@ -377,7 +371,7 @@ export default function VisualEditor( { styles } ) {
|
|
|
377
371
|
/>
|
|
378
372
|
<LayoutStyle
|
|
379
373
|
selector=".block-editor-block-list__layout.is-root-container"
|
|
380
|
-
layout={
|
|
374
|
+
layout={ postEditorLayout }
|
|
381
375
|
/>
|
|
382
376
|
{ align && (
|
|
383
377
|
<LayoutStyle css={ alignCSS } />
|
|
@@ -419,7 +413,7 @@ export default function VisualEditor( { styles } ) {
|
|
|
419
413
|
layout={ blockListLayout }
|
|
420
414
|
/>
|
|
421
415
|
</RecursionProvider>
|
|
422
|
-
</
|
|
416
|
+
</BlockCanvas>
|
|
423
417
|
</motion.div>
|
|
424
418
|
</motion.div>
|
|
425
419
|
</BlockTools>
|
|
@@ -67,3 +67,92 @@
|
|
|
67
67
|
// See also https://www.w3.org/TR/CSS22/visudet.html#the-height-property
|
|
68
68
|
flex-grow: 1;
|
|
69
69
|
}
|
|
70
|
+
|
|
71
|
+
// Fixed contextual toolbar
|
|
72
|
+
@include editor-left(".edit-post-visual-editor .block-editor-block-contextual-toolbar.is-fixed");
|
|
73
|
+
|
|
74
|
+
.edit-post-visual-editor .block-editor-block-contextual-toolbar.is-fixed {
|
|
75
|
+
position: sticky;
|
|
76
|
+
top: 0;
|
|
77
|
+
z-index: z-index(".block-editor-block-popover");
|
|
78
|
+
display: block;
|
|
79
|
+
width: 100%;
|
|
80
|
+
|
|
81
|
+
// on desktop and tablet viewports the toolbar is fixed
|
|
82
|
+
// on top of interface header
|
|
83
|
+
$toolbar-margin: $grid-unit-80 * 3 - 2 * $grid-unit + $grid-unit-05;
|
|
84
|
+
|
|
85
|
+
@include break-medium() {
|
|
86
|
+
// leave room for block inserter, undo and redo, list view
|
|
87
|
+
margin-left: $toolbar-margin;
|
|
88
|
+
// position on top of interface header
|
|
89
|
+
position: fixed;
|
|
90
|
+
top: $admin-bar-height;
|
|
91
|
+
// Don't fill up when empty
|
|
92
|
+
min-height: initial;
|
|
93
|
+
// remove the border
|
|
94
|
+
border-bottom: none;
|
|
95
|
+
// has to be flex for collapse button to fit
|
|
96
|
+
display: flex;
|
|
97
|
+
|
|
98
|
+
// Mimic the height of the parent, vertically align center, and provide a max-height.
|
|
99
|
+
height: $header-height;
|
|
100
|
+
align-items: center;
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
// on tablet viewports the toolbar is fixed
|
|
104
|
+
// on top of interface header and covers the whole header
|
|
105
|
+
// except for the inserter on the left
|
|
106
|
+
width: calc(100% - #{$toolbar-margin});
|
|
107
|
+
|
|
108
|
+
&.is-collapsed {
|
|
109
|
+
width: initial;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
&:empty {
|
|
113
|
+
width: initial;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.is-fullscreen-mode & {
|
|
117
|
+
// leave room for block inserter, undo and redo, list view
|
|
118
|
+
// and some margin left
|
|
119
|
+
margin-left: $grid-unit-80 * 4 - 2 * $grid-unit;
|
|
120
|
+
|
|
121
|
+
top: 0;
|
|
122
|
+
|
|
123
|
+
&.is-collapsed {
|
|
124
|
+
width: initial;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
&:empty {
|
|
128
|
+
width: initial;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.show-icon-labels & {
|
|
133
|
+
width: calc(100% + 40px - #{$toolbar-margin}); //there are no undo, redo and list view buttons
|
|
134
|
+
margin-left: $grid-unit-80 + 2 * $grid-unit; // inserter and margin
|
|
135
|
+
|
|
136
|
+
.is-fullscreen-mode & {
|
|
137
|
+
margin-left: $grid-unit * 18; // site hub, inserter and margin
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// on desktop viewports the toolbar is fixed
|
|
143
|
+
// on top of interface header and leaves room
|
|
144
|
+
// for the block inserter the publish button
|
|
145
|
+
@include break-large() {
|
|
146
|
+
width: auto;
|
|
147
|
+
.show-icon-labels & {
|
|
148
|
+
width: auto; //there are no undo, redo and list view buttons
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.is-fullscreen-mode & {
|
|
152
|
+
// in full screen mode we need to account for
|
|
153
|
+
// the combined with of the tools at the right of the header and the margin left
|
|
154
|
+
// of the toolbar which includes four buttons
|
|
155
|
+
width: calc(100% - 280px - #{4 * $grid-unit-80});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
package/src/editor.js
CHANGED
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
import { useMemo } from '@wordpress/element';
|
|
13
13
|
import { SlotFillProvider } from '@wordpress/components';
|
|
14
14
|
import { store as coreStore } from '@wordpress/core-data';
|
|
15
|
-
import { ShortcutProvider } from '@wordpress/keyboard-shortcuts';
|
|
16
15
|
import { store as preferencesStore } from '@wordpress/preferences';
|
|
17
16
|
import { CommandMenu } from '@wordpress/commands';
|
|
18
17
|
import { privateApis as coreCommandsPrivateApis } from '@wordpress/core-commands';
|
|
@@ -156,25 +155,23 @@ function Editor( { postId, postType, settings, initialEdits, ...props } ) {
|
|
|
156
155
|
}
|
|
157
156
|
|
|
158
157
|
return (
|
|
159
|
-
<
|
|
160
|
-
<
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
>
|
|
169
|
-
<
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
</SlotFillProvider>
|
|
177
|
-
</ShortcutProvider>
|
|
158
|
+
<SlotFillProvider>
|
|
159
|
+
<ExperimentalEditorProvider
|
|
160
|
+
settings={ editorSettings }
|
|
161
|
+
post={ post }
|
|
162
|
+
initialEdits={ initialEdits }
|
|
163
|
+
useSubRegistry={ false }
|
|
164
|
+
__unstableTemplate={ isTemplateMode ? template : undefined }
|
|
165
|
+
{ ...props }
|
|
166
|
+
>
|
|
167
|
+
<ErrorBoundary>
|
|
168
|
+
<CommandMenu />
|
|
169
|
+
<EditorInitialization postId={ postId } />
|
|
170
|
+
<Layout />
|
|
171
|
+
</ErrorBoundary>
|
|
172
|
+
<PostLockedModal />
|
|
173
|
+
</ExperimentalEditorProvider>
|
|
174
|
+
</SlotFillProvider>
|
|
178
175
|
);
|
|
179
176
|
}
|
|
180
177
|
|
|
@@ -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', () => {
|
package/src/style.scss
CHANGED
|
@@ -93,15 +93,6 @@ body.js.block-editor-page {
|
|
|
93
93
|
|
|
94
94
|
@include wordpress-admin-schemes();
|
|
95
95
|
|
|
96
|
-
.interface-interface-skeleton__header .edit-post-header {
|
|
97
|
-
@supports (scrollbar-gutter: stable) {
|
|
98
|
-
// The scrollbar-gutter property ensures space is reserved for the scrollbar to appear,
|
|
99
|
-
// when scrollbars are set to be always visible. This ensure icons stay visually aligned.
|
|
100
|
-
scrollbar-gutter: stable;
|
|
101
|
-
overflow: hidden;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
96
|
// The edit-site package adds or removes the sidebar when it's opened or closed.
|
|
106
97
|
// The edit-post package, however, always has the sidebar in the canvas.
|
|
107
98
|
// These edit-post specific rules ensures there isn't a border on the right of
|