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

Add/549 list block indent buttons #717

Merged
merged 24 commits into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
40472da
Add lists plugin to support list indenting correctly
tiny-james May 9, 2017
b19ee7f
Add onNodeChange as an optional entry in the Editable props
tiny-james May 9, 2017
2418990
Add indent/outdent buttons; list type buttons handle sublists
tiny-james May 9, 2017
d5c0d0b
Merge branch 'master' into add/549-list-block-indent-buttons
tiny-james May 10, 2017
5f2c3d0
Avoid use of global tinymce.activeEditor
tiny-james May 10, 2017
390e99a
Merge branch 'master' into add/549-list-block-indent-buttons
tiny-james May 11, 2017
ba33927
Allow the control.isActive function to be optional defaulting to false
tiny-james May 11, 2017
8dfdd74
Merge branch 'master' into add/549-list-block-indent-buttons
tiny-james May 12, 2017
1d93fbc
Merge branch 'master' into add/549-list-block-indent-buttons
tiny-james May 15, 2017
4cc20bf
Merge branch 'master' into add/549-list-block-indent-buttons
tiny-james May 15, 2017
f60e11d
Moved list logic into Editable
tiny-james May 16, 2017
abb531f
Removed onSetup and onNodeChange callbacks
tiny-james May 16, 2017
17a5168
Merge branch 'master' into add/549-list-block-indent-buttons
tiny-james May 17, 2017
1104141
Merge branch 'master' into add/549-list-block-indent-buttons
tiny-james May 17, 2017
27e1c0f
Put separate CSS selectors on different lines to improve readablity
tiny-james May 17, 2017
7156082
Merge branch 'master' into add/549-list-block-indent-buttons
tiny-james May 19, 2017
f8cce5a
Revert "Removed onSetup and onNodeChange callbacks"
tiny-james May 19, 2017
befe07b
Revert "Moved list logic into Editable"
tiny-james May 19, 2017
528f088
Removed onNodeChange; allow tinyMCE configuration outside Editable
tiny-james May 19, 2017
05288e1
Merge branch 'master' into add/549-list-block-indent-buttons
tiny-james May 22, 2017
68ab9ee
Remove onNodeChange property callback
tiny-james May 22, 2017
8e36e05
Renamed onConfig to getSettings
tiny-james May 22, 2017
9c5b029
Use find from lodash to avoid IE 11 support problems
tiny-james May 22, 2017
9ed5cf4
Replaced some out of position tab chars with spaces
tiny-james May 22, 2017
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
4 changes: 4 additions & 0 deletions blocks/components/editable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ export default class Editable extends wp.element.Component {
const focusPosition = this.getRelativePosition( element );
const bookmark = this.editor.selection.getBookmark( 2, true );
this.setState( { alignment, bookmark, formats, focusPosition } );

if ( this.props.onNodeChange ) {
this.props.onNodeChange( { element, parents } );
}
}

updateContent() {
Expand Down
1 change: 1 addition & 0 deletions blocks/components/editable/tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default class TinyMCE extends wp.element.Component {
browser_spellcheck: true,
entity_encoding: 'raw',
convert_urls: false,
plugins: [ 'lists' ],
setup: ( editor ) => {
this.editor = editor;
this.props.onSetup( editor );
Expand Down
60 changes: 51 additions & 9 deletions blocks/library/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,34 @@ import Editable from 'components/editable';

const { children, prop } = hpq;

function activeEditorExecCommand( command ) {
return () => {
const ed = tinymce.activeEditor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'd want to avoid using globals like this. We can't assume TinyMCE is even used for the Editable component here.


Unfortunately, it's very hard to find an alternative here. Maybe the "indent controls" should be considered as "inline toolbars" (the same way we do for formatting and alignment controls)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with that is we're moving code that likely no-one else is going to use into a common object purely to work around access issues. That doesn't appeal to me greatly either.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I managed to avoid using the global but it required passing the editor via a callback.

if ( ed ) {
ed.execCommand( command );
}
};
}

function listIsActive( listType ) {
return ( { nodeName = 'OL', internalListType } ) => {
return listType === ( internalListType ? internalListType : nodeName );
};
}

function listSetType( listType, editorCommand ) {
return ( { internalListType }, setAttributes ) => {
if ( internalListType ) {
// only change list types, don't toggle off internal lists
if ( internalListType !== listType ) {
activeEditorExecCommand( editorCommand )();
}
} else {
setAttributes( { nodeName: listType } );
}
};
}

registerBlock( 'core/list', {
title: wp.i18n.__( 'List' ),
icon: 'editor-ul',
Expand All @@ -21,22 +49,35 @@ registerBlock( 'core/list', {
{
icon: 'editor-ul',
title: wp.i18n.__( 'Convert to unordered' ),
isActive: ( { nodeName = 'OL' } ) => nodeName === 'UL',
onClick( attributes, setAttributes ) {
setAttributes( { nodeName: 'UL' } );
}
isActive: listIsActive( 'UL' ),
onClick: listSetType( 'UL', 'InsertUnorderedList' )
},
{
icon: 'editor-ol',
title: wp.i18n.__( 'Convert to ordered' ),
isActive: ( { nodeName = 'OL' } ) => nodeName === 'OL',
onClick( attributes, setAttributes ) {
setAttributes( { nodeName: 'OL' } );
}
}
isActive: listIsActive( 'OL' ),
onClick: listSetType( 'OL', 'InsertOrderedList' )
},
{
icon: 'editor-outdent',
title: wp.i18n.__( 'Outdent list item' ),
isActive: () => false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required to be defined? If so, we should probably update the behavior on rendering controls to allow it to be omitted (defaulting to false).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isActive is required as editor/modes/visual-editor/blocks.js calls it without checking if it already exists. It would be fairly easy to make it optional.

onClick: activeEditorExecCommand( 'Outdent' )
},
{
icon: 'editor-indent',
title: wp.i18n.__( 'Indent list item' ),
isActive: () => false,
onClick: activeEditorExecCommand( 'Indent' )
},
],

edit( { attributes, setAttributes, focus, setFocus } ) {
const onNodeChange = ( { parents } ) => {
const list = parents.find( ( node ) => node.nodeName === 'UL' || node.nodeName === 'OL' );
const internalListType = list ? list.nodeName : null;
setAttributes( { internalListType } );
};
const { nodeName = 'OL', values = [] } = attributes;
return (
<Editable
Expand All @@ -47,6 +88,7 @@ registerBlock( 'core/list', {
value={ values }
focus={ focus }
onFocus={ setFocus }
onNodeChange={ onNodeChange }
showAlignments
className="blocks-list" />
);
Expand Down
5 changes: 3 additions & 2 deletions blocks/library/list/style.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.blocks-list {
list-style-position: inside;
.blocks-list, .blocks-list ul, .blocks-list ol {
padding-left: 20px;
margin-left: 0;
}