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

Quote Block: Adding alignment controls to the quote block #511

Closed
wants to merge 5 commits into from

Conversation

youknowriad
Copy link
Contributor

This PR adds the alignment controls to the quote block #311

It also allows the block controls to be defined as an array of array. This creates multiple toolbars. Each array is a different toolbar.

@youknowriad youknowriad added the [Feature] Blocks Overall functionality of blocks label Apr 26, 2017
@youknowriad youknowriad self-assigned this Apr 26, 2017
<blockquote className={ `blocks-quote blocks-quote-style-${ style }` }>
<blockquote
className={ `blocks-quote blocks-quote-style-${ style }` }
style={ align ? { textAlign: align } : null }
Copy link
Member

Choose a reason for hiding this comment

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

Do we want the text alignment to apply to the entire quote (including citation), or just the paragraphs? cc @jasmussen

Copy link

@joyously joyously Apr 26, 2017

Choose a reason for hiding this comment

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

The text alignment only applies to the selected text, not a block. Float alignment applies to the whole block.

Copy link
Contributor Author

@youknowriad youknowriad Apr 27, 2017

Choose a reason for hiding this comment

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

Good question @joyously and @jasmussen might help to answer here. For me considering the alignment as inline controls is relevant for the continuous Text block #447.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I missed this. Yes it would be preferrable if we were able to have the alignments be per paragraph. Let me know if you'd like a mockup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can I ask for a clarification? Is this for the current quote block or for the continuous Text block? Yep, some mockups could be good :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the midstream correction on this one. Here's a mockup of a multi paragraph quote:

quote left aligned

Note how the caret is in text that is left aligned, therefore the toolbar shows the left alignment highlighted.

Now the first paragraph is right aligned:

quote right aligned

Note how the caret is inside the first paragraph.

Technically the behavior here would be the same as that of the "Continuous text" block.

@@ -133,6 +134,10 @@ class VisualEditorBlock extends wp.element.Component {

const { onSelect, onStartTyping, onHover, onMouseLeave, onFocus, onInsertAfter } = this.props;

const toolbars = settings.controls && settings.controls.length && ! Array.isArray( first( settings.controls ) )
Copy link
Member

@aduth aduth Apr 26, 2017

Choose a reason for hiding this comment

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

Ah, I had fun with this one, but alas, no obvious Lodash-fu will save it 😄

This is the closest I got, which has a few advantages; handles undefined controls, gracefully handles controls of mixed types (instead of testing first entry only), and always returns an array, even if empty, so that we don't need to test truthiness before mapping in the render below. But it's a little complex to behold.

reduce( settings.controls, ( memo, toolbar ) => (
	Array.isArray( toolbar )
		? [ ...memo, toolbar ]
		: [ ...memo.slice( 0, -1 ), [ ...( last( memo ) || [] ), toolbar ) ] ]
), [] );

At the very least, I'm not sure we need first, since we can be certain the array exists and has members at that point in the condition. Simply referencing the [ 0 ] entry should be enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I understand the magic here :P but it seems that if we have mixed values, the controls outside arrays are included in the previous array, which I think is not the desired behaviour if we ever have mixed controls. I'd think these "orphans" should be grouped together.

Yes. I'll drop the first, it seems enough for now to have only Arrays or only orphans

Copy link
Member

Choose a reason for hiding this comment

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

if we have mixed values, the controls outside arrays are included in the previous array, which I think is not the desired behaviour if we ever have mixed controls

I don't know that we'd want to encourage this anyways, but in the current implementation this will simply explode (trying to map on a non-array); thus the "graceful" remark.

@@ -33,16 +33,22 @@ msgid "List"
msgstr ""

#: blocks/library/list/index.js:25
#: blocks/library/quote/index.js:38
#: blocks/library/quote/index.js:37
Copy link
Member

Choose a reason for hiding this comment

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

Appears these got doubled up. Another npm run build should clear it up. Not certain what causes this.

@ellatrix ellatrix added this to the Prototype Parity milestone Apr 26, 2017
@aduth
Copy link
Member

aduth commented Apr 26, 2017

I added some clarifying comments in bd4e50f38b12090fe112ef73170160b4d615136b . It is maybe an overly complex solution, but I'm generally reluctant about logic which makes assumptions using only the first of potentially many entries in an array. Could maybe do for some tests too if we keep this.

@aduth
Copy link
Member

aduth commented Apr 26, 2017

Alternatively we could be a little less forgiving in the handling of singular values:

diff --git a/editor/modes/visual-editor/block.js b/editor/modes/visual-editor/block.js
index 76b9f2a..e60d117 100644
--- a/editor/modes/visual-editor/block.js
+++ b/editor/modes/visual-editor/block.js
@@ -142,7 +142,7 @@ class VisualEditorBlock extends wp.element.Component {
                                ? [ ...result, toolbar ]
                                // Singular values are appended to the last array in the result
                                //  Example: [ 1, 2, 3, 4 ] => [ [ 1, 2, 3, 4 ] ]
-                               : [ ...result.slice( 0, -1 ), [ ...( last( result ) || [] ), toolbar ] ]
+                               : [ [ ...( result[ 0 ] || [] ), toolbar ] ]
                ), [] );
 
                // Disable reason: Each block can receive focus but must be able to contain

@@ -133,6 +134,17 @@ class VisualEditorBlock extends wp.element.Component {

const { onSelect, onStartTyping, onHover, onMouseLeave, onFocus, onInsertAfter } = this.props;

// Normalize controls as an array of arrays (toolbars of controls)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe something like <div className="editor-toolbar__group"> should move to a separate component?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, but this component will have the following props : content, attributes, setAttributes. Or we could pass a block uid instead and duplicate setAttributes. Having attributes and setAttributes as props for a GroupedToolbars might not be a good idea.

@youknowriad
Copy link
Contributor Author

Per Slack Discussion, I've reverted to toolbars normalisation. Let me know if there's anything else here?

@aduth
Copy link
Member

aduth commented Apr 27, 2017

This comment chain still seems to be unresolved:

#511 (comment)

(Or at least lacking clarification)

@@ -159,14 +164,15 @@ class VisualEditorBlock extends wp.element.Component {
{ isSelected && ! isTyping &&
<div className="editor-visual-editor__block-controls">
<BlockSwitcher uid={ block.uid } />
{ !! settings.controls && (
{ toolbars.map( ( controls, index ) => (
Copy link
Member

Choose a reason for hiding this comment

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

This will error if a block doesn't define controls because toolbars will be undefined. We'll want to restore the truthy test or use Lodash's map.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants