@wordpress/edit-post 7.18.1-next.5a1d1283.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/header/index.js +6 -0
  3. package/build/components/header/index.js.map +1 -1
  4. package/build/components/layout/index.js +9 -3
  5. package/build/components/layout/index.js.map +1 -1
  6. package/build/components/start-page-options/index.js +2 -3
  7. package/build/components/start-page-options/index.js.map +1 -1
  8. package/build/components/visual-editor/index.js +34 -44
  9. package/build/components/visual-editor/index.js.map +1 -1
  10. package/build/editor.js +2 -3
  11. package/build/editor.js.map +1 -1
  12. package/build-module/components/header/index.js +6 -0
  13. package/build-module/components/header/index.js.map +1 -1
  14. package/build-module/components/layout/index.js +9 -3
  15. package/build-module/components/layout/index.js.map +1 -1
  16. package/build-module/components/start-page-options/index.js +2 -3
  17. package/build-module/components/start-page-options/index.js.map +1 -1
  18. package/build-module/components/visual-editor/index.js +35 -45
  19. package/build-module/components/visual-editor/index.js.map +1 -1
  20. package/build-module/editor.js +2 -3
  21. package/build-module/editor.js.map +1 -1
  22. package/build-style/style-rtl.css +94 -8
  23. package/build-style/style.css +94 -8
  24. package/package.json +32 -32
  25. package/src/components/header/index.js +2 -0
  26. package/src/components/keyboard-shortcut-help-modal/test/index.js +4 -5
  27. package/src/components/layout/index.js +9 -2
  28. package/src/components/preferences-modal/test/index.js +35 -8
  29. package/src/components/start-page-options/index.js +4 -5
  30. package/src/components/visual-editor/index.js +49 -55
  31. package/src/components/visual-editor/style.scss +89 -0
  32. package/src/editor.js +17 -20
  33. package/src/style.scss +0 -9
  34. package/src/components/preferences-modal/test/__snapshots__/index.js.snap +0 -942
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { render, screen } from '@testing-library/react';
4
+ import { render, screen, within } from '@testing-library/react';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
@@ -20,25 +20,52 @@ jest.mock( '@wordpress/compose/src/hooks/use-viewport-match', () => jest.fn() );
20
20
 
21
21
  describe( 'EditPostPreferencesModal', () => {
22
22
  describe( 'should match snapshot when the modal is active', () => {
23
+ afterEach( () => {
24
+ useViewportMatch.mockClear();
25
+ } );
23
26
  it( 'large viewports', async () => {
24
27
  useSelect.mockImplementation( () => [ true, true, false ] );
25
28
  useViewportMatch.mockImplementation( () => true );
26
29
  render( <EditPostPreferencesModal /> );
27
- await screen.findByRole( 'tab', {
30
+ const tabPanel = await screen.findByRole( 'tabpanel', {
28
31
  name: 'General',
29
- selected: true,
30
32
  } );
33
+
31
34
  expect(
32
- screen.getByRole( 'dialog', { name: 'Preferences' } )
33
- ).toMatchSnapshot();
35
+ within( tabPanel ).getByLabelText(
36
+ 'Include pre-publish checklist'
37
+ )
38
+ ).toBeInTheDocument();
34
39
  } );
35
- it( 'small viewports', () => {
40
+ it( 'small viewports', async () => {
36
41
  useSelect.mockImplementation( () => [ true, true, false ] );
37
42
  useViewportMatch.mockImplementation( () => false );
38
43
  render( <EditPostPreferencesModal /> );
44
+
45
+ // The tabpanel is not rendered in small viewports.
46
+ expect(
47
+ screen.queryByRole( 'tabpanel', {
48
+ name: 'General',
49
+ } )
50
+ ).not.toBeInTheDocument();
51
+
52
+ const dialog = screen.getByRole( 'dialog', {
53
+ name: 'Preferences',
54
+ } );
55
+
56
+ // Checkbox toggle controls are not rendered in small viewports.
57
+ expect(
58
+ within( dialog ).queryByLabelText(
59
+ 'Include pre-publish checklist'
60
+ )
61
+ ).not.toBeInTheDocument();
62
+
63
+ // Individual preference nav buttons are rendered in small viewports.
39
64
  expect(
40
- screen.getByRole( 'dialog', { name: 'Preferences' } )
41
- ).toMatchSnapshot();
65
+ within( dialog ).getByRole( 'button', {
66
+ name: 'General',
67
+ } )
68
+ ).toBeInTheDocument();
42
69
  } );
43
70
  } );
44
71
 
@@ -97,14 +97,13 @@ function StartPageOptionsModal() {
97
97
 
98
98
  export default function StartPageOptions() {
99
99
  const shouldEnableModal = useSelect( ( select ) => {
100
- const { getEditedPostContent, isEditedPostSaveable } =
101
- select( editorStore );
100
+ const { isCleanNewPost } = select( editorStore );
102
101
  const { isEditingTemplate, isFeatureActive } = select( editPostStore );
102
+
103
103
  return (
104
- ! isEditedPostSaveable() &&
105
- '' === getEditedPostContent() &&
106
104
  ! isEditingTemplate() &&
107
- ! isFeatureActive( 'welcomeGuide' )
105
+ ! isFeatureActive( 'welcomeGuide' ) &&
106
+ isCleanNewPost()
108
107
  );
109
108
  }, [] );
110
109
 
@@ -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 { LayoutStyle, useLayoutClasses, useLayoutStyles } = unlock(
41
- blockEditorPrivateApis
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 ( getCurrentPostType() === 'wp_block' ) {
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
- <MaybeIframe
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={ blockListLayout }
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
- </MaybeIframe>
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
- <ShortcutProvider>
160
- <SlotFillProvider>
161
- <ExperimentalEditorProvider
162
- settings={ editorSettings }
163
- post={ post }
164
- initialEdits={ initialEdits }
165
- useSubRegistry={ false }
166
- __unstableTemplate={ isTemplateMode ? template : undefined }
167
- { ...props }
168
- >
169
- <ErrorBoundary>
170
- <CommandMenu />
171
- <EditorInitialization postId={ postId } />
172
- <Layout />
173
- </ErrorBoundary>
174
- <PostLockedModal />
175
- </ExperimentalEditorProvider>
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
 
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