Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move document information and outline to list view panel #44788

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/components/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export {
Polygon,
Rect,
G,
Line,
HorizontalRule,
BlockQuotation,
} from '@wordpress/primitives';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe( 'Navigating the block hierarchy', () => {
// Navigate to the third column in the columns block.
await pressKeyWithModifier( 'ctrl', '`' );
await pressKeyWithModifier( 'ctrl', '`' );
await pressKeyTimes( 'Tab', 2 );
await pressKeyTimes( 'Tab', 4 );
await pressKeyTimes( 'ArrowDown', 4 );
await page.waitForSelector(
'.is-highlighted[aria-label="Block: Column (3 of 3)"]'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
store as blockEditorStore,
} from '@wordpress/block-editor';
import {
TableOfContents,
EditorHistoryRedo,
EditorHistoryUndo,
store as editorStore,
Expand Down Expand Up @@ -77,13 +76,6 @@ function HeaderToolbar() {
);
const overflowItems = (
<>
<ToolbarItem
as={ TableOfContents }
hasOutlineItemsDisabled={ isTextModeEnabled }
repositionDropdown={ showIconLabels && ! isWideViewport }
showTooltip={ ! showIconLabels }
variant={ showIconLabels ? 'tertiary' : undefined }
/>
<ToolbarItem
as={ Button }
className="edit-post-header-toolbar__list-view-toggle"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import {
DocumentOutline,
WordCount,
TimeToRead,
CharacterCount,
} from '@wordpress/editor';
import { store as blockEditorStore } from '@wordpress/block-editor';
import {
__experimentalText as Text,
Path,
SVG,
Line,
Rect,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';

function EmptyOutlineIllustration() {
return (
<SVG
width="138"
height="148"
viewBox="0 0 138 148"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<Rect width="138" height="148" rx="4" fill="#F0F6FC" />
<Line x1="44" y1="28" x2="24" y2="28" stroke="#DDDDDD" />
<Rect x="48" y="16" width="27" height="23" rx="4" fill="#DDDDDD" />
<Path
d="M54.7585 32V23.2727H56.6037V26.8736H60.3494V23.2727H62.1903V32H60.3494V28.3949H56.6037V32H54.7585ZM67.4574 23.2727V32H65.6122V25.0241H65.5611L63.5625 26.277V24.6406L65.723 23.2727H67.4574Z"
fill="black"
/>
<Line x1="55" y1="59" x2="24" y2="59" stroke="#DDDDDD" />
<Rect x="59" y="47" width="29" height="23" rx="4" fill="#DDDDDD" />
<Path
d="M65.7585 63V54.2727H67.6037V57.8736H71.3494V54.2727H73.1903V63H71.3494V59.3949H67.6037V63H65.7585ZM74.6605 63V61.6705L77.767 58.794C78.0313 58.5384 78.2528 58.3082 78.4318 58.1037C78.6136 57.8991 78.7514 57.6989 78.8452 57.5028C78.9389 57.304 78.9858 57.0895 78.9858 56.8594C78.9858 56.6037 78.9276 56.3835 78.8111 56.1989C78.6946 56.0114 78.5355 55.8679 78.3338 55.7685C78.1321 55.6662 77.9034 55.6151 77.6477 55.6151C77.3807 55.6151 77.1477 55.669 76.9489 55.777C76.75 55.8849 76.5966 56.0398 76.4886 56.2415C76.3807 56.4432 76.3267 56.6832 76.3267 56.9616H74.5753C74.5753 56.3906 74.7045 55.8949 74.9631 55.4744C75.2216 55.054 75.5838 54.7287 76.0497 54.4986C76.5156 54.2685 77.0526 54.1534 77.6605 54.1534C78.2855 54.1534 78.8295 54.2642 79.2926 54.4858C79.7585 54.7045 80.1207 55.0085 80.3793 55.3977C80.6378 55.7869 80.767 56.233 80.767 56.7358C80.767 57.0653 80.7017 57.3906 80.571 57.7116C80.4432 58.0327 80.2145 58.3892 79.8849 58.7812C79.5554 59.1705 79.0909 59.6378 78.4915 60.1832L77.2173 61.4318V61.4915H80.8821V63H74.6605Z"
fill="black"
/>
<Line x1="80" y1="90" x2="24" y2="90" stroke="#DDDDDD" />
<Rect x="84" y="78" width="30" height="23" rx="4" fill="#F0B849" />
<Path
d="M90.7585 94V85.2727H92.6037V88.8736H96.3494V85.2727H98.1903V94H96.3494V90.3949H92.6037V94H90.7585ZM99.5284 92.4659V91.0128L103.172 85.2727H104.425V87.2841H103.683L101.386 90.919V90.9872H106.564V92.4659H99.5284ZM103.717 94V92.0227L103.751 91.3793V85.2727H105.482V94H103.717Z"
fill="black"
/>
<Line x1="66" y1="121" x2="24" y2="121" stroke="#DDDDDD" />
<Rect x="70" y="109" width="29" height="23" rx="4" fill="#DDDDDD" />
<Path
d="M76.7585 125V116.273H78.6037V119.874H82.3494V116.273H84.1903V125H82.3494V121.395H78.6037V125H76.7585ZM88.8864 125.119C88.25 125.119 87.6832 125.01 87.1861 124.791C86.6918 124.57 86.3011 124.266 86.0142 123.879C85.7301 123.49 85.5838 123.041 85.5753 122.533H87.4332C87.4446 122.746 87.5142 122.933 87.642 123.095C87.7727 123.254 87.946 123.378 88.1619 123.466C88.3778 123.554 88.6207 123.598 88.8906 123.598C89.1719 123.598 89.4205 123.548 89.6364 123.449C89.8523 123.349 90.0213 123.212 90.1435 123.036C90.2656 122.859 90.3267 122.656 90.3267 122.426C90.3267 122.193 90.2614 121.987 90.1307 121.808C90.0028 121.626 89.8182 121.484 89.5767 121.382C89.3381 121.28 89.054 121.229 88.7244 121.229H87.9105V119.874H88.7244C89.0028 119.874 89.2486 119.825 89.4616 119.729C89.6776 119.632 89.8452 119.499 89.9645 119.328C90.0838 119.155 90.1435 118.953 90.1435 118.723C90.1435 118.504 90.0909 118.312 89.9858 118.148C89.8835 117.98 89.7386 117.849 89.5511 117.756C89.3665 117.662 89.1506 117.615 88.9034 117.615C88.6534 117.615 88.4247 117.661 88.2173 117.751C88.0099 117.839 87.8438 117.966 87.7188 118.131C87.5938 118.295 87.527 118.489 87.5185 118.71H85.75C85.7585 118.207 85.902 117.764 86.1804 117.381C86.4588 116.997 86.8338 116.697 87.3054 116.482C87.7798 116.263 88.3153 116.153 88.9119 116.153C89.5142 116.153 90.0412 116.263 90.4929 116.482C90.9446 116.7 91.2955 116.996 91.5455 117.368C91.7983 117.737 91.9233 118.152 91.9205 118.612C91.9233 119.101 91.7713 119.509 91.4645 119.835C91.1605 120.162 90.7642 120.369 90.2756 120.457V120.526C90.9176 120.608 91.4063 120.831 91.7415 121.195C92.0795 121.555 92.2472 122.007 92.2443 122.55C92.2472 123.047 92.1037 123.489 91.8139 123.875C91.527 124.261 91.1307 124.565 90.625 124.787C90.1193 125.009 89.5398 125.119 88.8864 125.119Z"
fill="black"
/>
</SVG>
);
}

export default function ListViewOutline() {
const { headingCount } = useSelect( ( select ) => {
const { getGlobalBlockCount } = select( blockEditorStore );
return {
headingCount: getGlobalBlockCount( 'core/heading' ),
};
}, [] );
return (
<>
{ headingCount > 0 ? (
<DocumentOutline />
) : (
<div className="edit-post-editor__list-view-empty-headings">
<EmptyOutlineIllustration />
<p>
{ __(
'Navigate the structure of your document and address issues like empty or incorrect heading levels.'
) }
</p>
</div>
) }
<div className="edit-post-editor__list-view-overview">
<div>
<Text>{ __( 'Characters:' ) }</Text>
<Text>
<CharacterCount />
</Text>
</div>
<div>
<Text>{ __( 'Words:' ) }</Text>
<WordCount />
</div>
<div>
<Text>{ __( 'Time to read:' ) }</Text>
<TimeToRead />
</div>
</div>
</>
);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
Expand All @@ -6,18 +11,19 @@ import { Button } from '@wordpress/components';
import {
useFocusOnMount,
useFocusReturn,
useInstanceId,
useMergeRefs,
} from '@wordpress/compose';
import { useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { closeSmall } from '@wordpress/icons';
import { ESCAPE } from '@wordpress/keycodes';
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import { store as editPostStore } from '../../store';
import ListViewOutline from './list-view-outline';

export default function ListViewSidebar() {
const { setIsListViewOpened } = useDispatch( editPostStore );
Expand All @@ -32,35 +38,68 @@ export default function ListViewSidebar() {
}
}

const instanceId = useInstanceId( ListViewSidebar );
const labelId = `edit-post-editor__list-view-panel-label-${ instanceId }`;
const [ tab, setTab ] = useState( 'list-view' );

return (
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
<div
aria-labelledby={ labelId }
aria-label={ __( 'List View' ) }
className="edit-post-editor__list-view-panel"
onKeyDown={ closeOnEscape }
>
<div
className="edit-post-editor__list-view-panel-header"
className="edit-post-editor__list-view-panel-header components-panel__header edit-post-sidebar__panel-tabs"
ref={ headerFocusReturnRef }
>
<strong id={ labelId }>{ __( 'List View' ) }</strong>
jorgefilipecosta marked this conversation as resolved.
Show resolved Hide resolved
<Button
icon={ closeSmall }
label={ __( 'Close List View Sidebar' ) }
onClick={ () => setIsListViewOpened( false ) }
/>
<ul>
jorgefilipecosta marked this conversation as resolved.
Show resolved Hide resolved
<li>
<Button
onClick={ () => {
setTab( 'list-view' );
} }
className={ classnames(
'edit-post-sidebar__panel-tab',
{ 'is-active': tab === 'list-view' }
) }
aria-current={ tab === 'list-view' }
>
{ __( 'List View' ) }
</Button>
</li>
<li>
<Button
onClick={ () => {
setTab( 'outline' );
} }
className={ classnames(
'edit-post-sidebar__panel-tab',
{ 'is-active': tab === 'outline' }
) }
aria-current={ tab === 'outline' }
>
{ __( 'Outline' ) }
</Button>
</li>
</ul>
jorgefilipecosta marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div
className="edit-post-editor__list-view-panel-content"
ref={ useMergeRefs( [
contentFocusReturnRef,
focusOnMountRef,
] ) }
className="edit-post-editor__list-view-container"
>
<ListView />
{ tab === 'list-view' && (
<div className="edit-post-editor__list-view-panel-content">
<ListView />
</div>
) }
{ tab === 'outline' && <ListViewOutline /> }
</div>
</div>
);
Expand Down
72 changes: 64 additions & 8 deletions packages/edit-post/src/components/secondary-sidebar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
.edit-post-editor__list-view-panel {
// Same width as the Inserter.
// @see packages/block-editor/src/components/inserter/style.scss
min-width: 350px;
// Width of the list view panel.
width: 350px;

.edit-post-sidebar__panel-tabs {
flex-direction: row-reverse;
}
}

.edit-post-editor__inserter-panel-header {
Expand All @@ -18,30 +23,81 @@
justify-content: flex-end;
}

.edit-post-editor__inserter-panel-content,
.edit-post-editor__list-view-panel-content {
.edit-post-editor__inserter-panel-content {
// Leave space for the close button
height: calc(100% - #{$button-size} - #{$grid-unit-10});
}

.edit-post-editor__inserter-panel-content {
@include break-medium() {
height: 100%;
}
}

.edit-post-editor__list-view-panel-header {
align-items: center;
border-bottom: $border-width solid $gray-300;
display: flex;
justify-content: space-between;
height: $grid-unit-60;
padding-left: $grid-unit-20;
padding-right: $grid-unit-05;
ul {
width: calc(100% - #{ $grid-unit-50 });
}
li {
width: 50%;
button {
width: 100%;
text-align: initial;
}
}
li:only-child {
width: 100%;
}
}

.edit-post-editor__list-view-panel-content {
.edit-post-editor__list-view-panel-content,
.edit-post-editor__list-view-container > .document-outline,
.edit-post-editor__list-view-empty-headings {
overflow-x: hidden;
overflow-y: auto;
height: 100%;
// The table cells use an extra pixels of space left and right. We compensate for that here.
padding: $grid-unit-10 ($grid-unit-10 - $border-width - $border-width);
}

.edit-post-editor__list-view-empty-headings {
& > svg {
margin-top: $grid-unit-30 + $grid-unit-05;
}
& > p {
padding-left: $grid-unit-40;
padding-right: $grid-unit-40;
}
text-align: center;
color: $gray-700;
}

.edit-post-editor__list-view-overview {
& > div > span:first-child {
// Width of the text information fields.
width: 90px;
jorgefilipecosta marked this conversation as resolved.
Show resolved Hide resolved
display: inline-block;
}
border-top: $border-width solid $gray-300;
width: calc(100% - #{ $grid-unit-40 });
padding: $grid-unit-20;
& > div {
padding: 0 0 $grid-unit-10;
& > span {
font-size: $helptext-font-size;
line-height: $default-line-height;
color: $gray-700;
}
}
// Height of the overview container.
height: 72px;
}

.edit-post-editor__list-view-container {
display: flex;
flex-direction: column;
height: calc(100% - #{$grid-unit-60});
}
2 changes: 2 additions & 0 deletions packages/editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export { default as TableOfContents } from './table-of-contents';
export { default as ThemeSupportCheck } from './theme-support-check';
export { default as UnsavedChangesWarning } from './unsaved-changes-warning';
export { default as WordCount } from './word-count';
export { default as TimeToRead } from './time-to-read';
export { default as CharacterCount } from './character-count';

// State Related Components.
export { default as EditorProvider } from './provider';
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/components/time-to-read/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function TimeToRead() {
const minutesToReadString =
minutesToRead === 0
? createInterpolateElement( __( '<span>< 1</span> minute' ), {
span: <span className="table-of-contents__number" />,
span: <span />,
} )
: createInterpolateElement(
sprintf(
Expand All @@ -51,7 +51,7 @@ export default function TimeToRead() {
minutesToRead
),
{
span: <span className="table-of-contents__number" />,
span: <span />,
}
);

Expand Down
7 changes: 7 additions & 0 deletions packages/primitives/src/svg/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export const Circle = ( props ) => createElement( 'circle', props );
*/
export const G = ( props ) => createElement( 'g', props );

/**
* @param {import('react').ComponentPropsWithoutRef<'line'>} props
*
* @return {JSX.Element} Path component
*/
export const Line = ( props ) => createElement( 'line', props );

/**
* @param {import('react').ComponentPropsWithoutRef<'path'>} props
*
Expand Down
1 change: 1 addition & 0 deletions packages/primitives/src/svg/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export {
RadialGradient,
LinearGradient,
Stop,
Line,
} from 'react-native-svg';

const AnimatedSvg = Animated.createAnimatedComponent(
Expand Down