Skip to content
This repository was archived by the owner on Nov 6, 2022. It is now read-only.

Add rich text control#221

Merged
lukecarbis merged 35 commits intodevelopfrom
feature/rich-text
Jun 18, 2019
Merged

Add rich text control#221
lukecarbis merged 35 commits intodevelopfrom
feature/rich-text

Conversation

@lukecarbis
Copy link
Copy Markdown
Member

@lukecarbis lukecarbis commented Jan 21, 2019

Resolves #20.

@lukecarbis lukecarbis requested a review from RobStino January 21, 2019 10:46
@RobStino
Copy link
Copy Markdown
Collaborator

@lukecarbis See above for conflicts notice.

@RobStino
Copy link
Copy Markdown
Collaborator

@lukecarbis Without this option checked, I still get new paragraphs when I create a new line.
image
image

@RobStino
Copy link
Copy Markdown
Collaborator

I noticed that the Rich Text controls disappear when typing. This felt weird, but then I checked the normal paragraph block and noticed that the behaviour is the same there.
See this vid for what I mean
https://d.pr/v/Ja6liq

Also, is it possible to get the text alignment options?
image

@lukecarbis lukecarbis changed the title Add rich text control [WIP] Add rich text control Jan 22, 2019
@RobStino
Copy link
Copy Markdown
Collaborator

Hey @lukecarbis
Testing this further this morning and saw this bug.
Basically, I can't seem to go back to an empty state for the rich text field.
https://d.pr/v/0k0AuY

@kienstra
Copy link
Copy Markdown
Collaborator

Looks Good
Alignment Buttons

Hi @lukecarbis,
This PR looks good. If it would help, I'm working on a commit that adds alignment buttons:

alignment-buttons

@davidallenlewis
Copy link
Copy Markdown

This is awesome. Looking forward to it being merged.

I would like to see a format menu for headers though and a list option. You can use separate blocks for headings and lists but if your rich text is part of a larger "format" style block (say a 2 column image + text block with a background colour / image) it would be nice to have lists and headers. No more than that though. Keep it simple.

@lukecarbis lukecarbis added this to the 1.3 milestone Apr 11, 2019
@dave-smyth
Copy link
Copy Markdown

This might be a nightmare to implement, but it would be amazing if there was some way to control the options that are available in the editor. For instance, in some cases it would be useful to limit them to multiple lines of text only (no formatting other than bold and italic, perhaps), other times headings might be useful and in some cases alignment might be good, too.

Perhaps the editor could have three settings (minimal, standard, full) that would enable different levels of control.

Minimal: multiple lines, bold, italic, links
Standard: minimal + headings, lists
Full: everything else

@AndrewSheetMetal
Copy link
Copy Markdown

Hey guys, just a quick question:

We need this feature for a project. How is the progress? When can we expect this feature to be distributed in a release?
Thanks!

@lukecarbis
Copy link
Copy Markdown
Member Author

@AndrewSheetMetal We're hoping to release it in our 1.3 milestone, which we're working on right now. :)

kienstra added 3 commits May 26, 2019 23:38
There were 2 conflicts:
js/blocks/loader/editor.scss
 - retained both edits
php/post-types/class-block-post.php
 - retained the edits in the develop branch,
as the means of instantiating controls changed.
Use the $name property in each class
to store them in the  property,
instead of the name in $control_names.
This is very straight-forward,
and very similar to other control text classes.
@kienstra
Copy link
Copy Markdown
Collaborator

Question About Alignment Controls

Hi @lukecarbis and @RobStino,
Hope you had a great weekend.

Would you like the Rich Text control to have alignment controls?

Below is the current Rich Text control, with the possible location of alignment controls.

I liked the location here better, maybe the API changed in the meantime.

rich-text-current

I'm not sure if it's possible to get the RichText to display the alignment selected, though. For example, on clicking "Align text right," it'd be best if the RichText showed everything aligned to the right:

alignment-here

If you'd like alignment controls, I'll look at this more.

Thanks!

@kienstra
Copy link
Copy Markdown
Collaborator

kienstra commented May 27, 2019

This PR already worked pretty well, even before I made some commits above. The .gif above shows the current state.

All of the controls shown above are included in the RichText by default, including Code, Inline Image, and Strikethrough. Except for the alignment controls shown above.

@lukecarbis
Copy link
Copy Markdown
Member Author

@kienstra I like the earlier version of the alignment controls better too (where they're not hidden behind a dropdown). But if that's no longer easily possible, I don't have that strong feelings about it.

Showing how the alignment effects the text, however, is very important. Without it, I'm sure I would think it was a bug.

@kienstra
Copy link
Copy Markdown
Collaborator

Hi @lukecarbis,
Thanks for looking at this.

@kienstra I like the earlier version of the alignment controls better too (where they're not hidden behind a dropdown). But if that's no longer easily possible, I don't have that strong feelings about it.

Yeah, that display was better. I'll look at if it's still possible.

Showing how the alignment effects the text, however, is very important. Without it, I'm sure I would think it was a bug.

Good point. I'll also work on this.

Copy link
Copy Markdown
Member Author

@lukecarbis lukecarbis left a comment

Choose a reason for hiding this comment

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

I can't approve / request changes since this is my PR… but so far it looks great. Haven't yet been able to test alignment controls. Is that committed yet? I couldn't find them.

Screen Shot 2019-05-28 at 8 16 17 am

A few minor suggestions, plus getting the alignment controls working is important. Alignment + Paragraphs is the challenging part, I believe!

'sanitize' => 'sanitize_text_field',
)
);
$this->settings[] = new Control_Setting(
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmm… what do you think… should we?

a) Remove this option entirely, and force new paragraphs. This is "rich text" and so paragraphs should be expected
b) Enable this by default. I would expect paragraphs in rich text
c) Use the same setting labels / options as we recently implemented for the textarea (doesn't work quite the same though since the textarea isn't an imported control with a multiline option)
d) Leave as it (but maybe better align the Help text and Label to the textarea setting?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@RobStino I'd love your thoughts on this, too. I'm leaning toward option A. What's a use case for not automatically creating paragraphs with a rich text field?

* @return void
*/
public function register_settings() {
$this->settings[] = new Control_Setting(
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We should also find a way of disabling the "Field Location" setting, or forcing the Editor option, since it simply doesn't work when loaded in the Inspector.

Screen Shot 2019-05-28 at 8 26 46 am

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah, good catch.

@lukecarbis lukecarbis changed the title [WIP] Add rich text control Add rich text control May 27, 2019
@kienstra
Copy link
Copy Markdown
Collaborator

kienstra commented May 27, 2019

Haven't yet been able to test alignment controls. Is that committed yet?

No, I just have it locally in a messy commit 😄It's not working in the sense of applying the alignment in the editor.

@RobStino
Copy link
Copy Markdown
Collaborator

Hey all.
Testing this and it's looking good. Everything so far is behaving as expected.
Re the field setting for having enter start a new paragraph. I think this should be the default and actually be removed as a setting altogether. I can't think of a good use case otherwise. Also, shift + enter creates a break tag anyway so I think we're covered.
Looking forward to testing the alignment controls.

@RobStino
Copy link
Copy Markdown
Collaborator

Seeing that the control just doesn't work in the Inspector, I think we don't make it an option for this particular field. For now at least.

@kienstra
Copy link
Copy Markdown
Collaborator

Re the field setting for having enter start a new paragraph. I think this should be the default and actually be removed as a setting altogether. I can't think of a good use case otherwise. Also, shift + enter creates a break tag anyway so I think we're covered.

Good point. Unless there are other ideas, I'll remove the 'Use Paragraphs' option for now.

As Rob and Luke mentioned,
this isn't very helpful for the Rich Text control.
This keeps the same border-right
that is applied with native Gutenberg styles.
@kienstra
Copy link
Copy Markdown
Collaborator

Hi @lukecarbis,
Thanks a lot for reviewing this.

+1 for not selecting the whole line of text to realign it.

Sure, that's applied now.

Buttons looks good to me. They match the paragraph block. Just one very minor glitch:

How does the fix in d3901de look?

border-here

I'm seeing some screwy behaviour with new lines after alignment. Are we intending to break aligned text into a div? Should it be a paragraph?

Good point, f7983f6 makes aligned text and new lines <p> tags.

Also, is it possible to style the text in the rich text area to better match a standard textarea? Something as simple as reducing the font size would makes a big difference.

Yeah, 13px would make this look more like the Text Area control.

To me, it looks a little small, though:

13-px-font-size

@lukecarbis
Copy link
Copy Markdown
Member Author

@RobStino Can we get a third opinion on the text size? I prefer it smaller (matching a textarea).

@lukecarbis
Copy link
Copy Markdown
Member Author

Looks great! Some thoughts here: https://www.fromsmash.com/n-8KJbnS-f-c0

@RobStino
Copy link
Copy Markdown
Collaborator

Hey friends
Epic work Ryan btw!
Couple of things:

  • I agree with 13px. Keeping font size consistent between similar style fields is important I think.
  • the grey highlight you get is the same experience you get when formatting text in a regular text Block. I’m guessing this is where this has come from.
  • this carry over behaviour is probably what is causing the issue Luke spotted when he added a character to the same line as the centre aligned text.

kienstra added 2 commits June 3, 2019 22:16
As Luke pointed out,
an alignment format should be selected even
if the cursor is at the border,
like the end of a line.
It should be possible to put the cursor at the
end of a centered line and enter more centered text.
This implements that.
If the line is centered, and the cursor is
at the end of it,
ensure the center formatting control
is active, and can be toggled off.
@kienstra
Copy link
Copy Markdown
Collaborator

kienstra commented Jun 4, 2019

The commits above partially address the testing comments. There's still more work needed, though.

@kienstra
Copy link
Copy Markdown
Collaborator

kienstra commented Jun 4, 2019

Finishing the alignment controls (left, center, and right) could take at least a few more days. The behavior for alignment controls is a little different from the other controls, like bold.

For example, as mentioned above, placing a cursor at the end of a centered line and typing line should result in more centered text, not a new line.

But the built-in behavior of the RichText, like for bold or italic, is that it doesn't continue the formatting. It wouldn't be bold on placing a cursor at the end of bold text and typing. So I've been overriding the RichText component to accommodate the alignment controls.

Before, I simply removed this,
where I should have moved it.
@lukecarbis
Copy link
Copy Markdown
Member Author

Just had a look through the code. Obviously having to extend the rich text is not ideal, but your implementation is really neat, there's obviously no other way to get alignment working the way we'd like it to.

Nice work!

@kienstra
Copy link
Copy Markdown
Collaborator

kienstra commented Jun 5, 2019

Obviously having to extend the rich text is not ideal, but your implementation is really neat, there's obviously no other way to get alignment working the way we'd like it to.

Thanks, @lukecarbis! Didn't want it to seem like I was complaining, just explaining it was taking a while 😄

@lukecarbis lukecarbis mentioned this pull request Jun 6, 2019
@kienstra
Copy link
Copy Markdown
Collaborator

kienstra commented Jun 10, 2019

Extending RichText

Extending the RichText component isn't working locally so far.

Extending it looks to be necessary for certain behaviors of the alignment controls to work.

For example, I've been working on a class:

const { RichText } = wp.editor;
const { LEFT, RIGHT } = wp.keycodes;
const { getComputedStyle, isCollapsed } = wp.richText;

/**
 * Browser dependencies
 */
const { getSelection } = window;

class BlockLabRichText extends RichText {


	/**
	 * Constructs the component class.
	 */
	constructor() {
		super( ...arguments );
		this.onSelectionChange = this.onSelectionChange.bind( this );
		this.onKeyDown = this.onKeyDown.bind( this );
		this.handleHorizontalNavigation = this.handleHorizontalNavigation.bind( this );
		this.onPointerDown = this.onPointerDown.bind( this );
	}

	/**
	 * Overrides the parent implementation of the `selectionchange` handler.
	 *
	 * Mainly copies the parent implemetation.
	 * The main difference is that this allows selecting the entire format by clicking on its border.
	 */
	onSelectionChange() {
		...
	}

	/* etc... */
}

But this class isn't using onSelectionChange above or the other extending methods. It's simply using the onSelectionChange() method in the parent RichText class when I debug this.

I'll keep looking at this, but it might not be possible to override these methods in the class to get the expected behavior for the alignment controls.

@lukecarbis
Copy link
Copy Markdown
Member Author

lukecarbis commented Jun 10, 2019

@kienstra It might be best to pull alignment controls entirely in that case, and put them in a separate issue.

As we've discussed,
this needs different behavior than the
default alignment controls,
like bold and italic.
@kienstra
Copy link
Copy Markdown
Collaborator

Alignment Controls Removed

Hi @lukecarbis,
Thanks a lot for your ideas for the alignment controls.

I couldn't get them to work, including with the onChangeAlign() method.

This would probably need to extend RichText somehow, but like we talked about, that's not recommended in React.

The behavior of the default formats like bold is different from the alignment formats in a few ways. I don't see a way to accommodate the alignment formats.

For example:
centered-this

@lukecarbis
Copy link
Copy Markdown
Member Author

Without alignment controls, this works brilliantly. I can't approve, since I started the request, but this has my green tick.

Just one topic of discussion. What do you think about reducing the gap between paragraphs from 0.1em to something a little lower? 0.67em looks a little nicer, in my opinion, and still provides a clear distinction between paragraph break and line break. Very minor difference:

Screen Shot 2019-06-12 at 9 33 29 am
Screen Shot 2019-06-12 at 9 33 06 am

This looks better,
as there isn't quite so much space in the Rich Text
control between the paragraphs (line-breaks).
@kienstra
Copy link
Copy Markdown
Collaborator

Hi @lukecarbis,
Good idea. How does a5856e5 look?

It uses you idea of reducing the margins:

paragraph-tags

Also, it removes the FORMATTING_CONTROLS constant, as it was simply the default value in RichText.

@lukecarbis
Copy link
Copy Markdown
Member Author

Great work Ryan.

✅ Review passed.

@kienstra
Copy link
Copy Markdown
Collaborator

Thanks, Luke! Thanks a lot for your work on this.

Copy link
Copy Markdown
Collaborator

@RobStino RobStino left a comment

Choose a reason for hiding this comment

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

Hi everyone.
Sorry for the big delays on reviewing this PR.
Tested in my local and everything looks really good!

Adding a Rich Text Field to a new Block
image

Adding the block in the Editor
image

Previewing in the Editor
image

On the front end
image

@kienstra
Copy link
Copy Markdown
Collaborator

Thanks!

Hi @RobStino,
All good, thanks a lot for testing this!

@lukecarbis lukecarbis merged commit 255a416 into develop Jun 18, 2019
@lukecarbis lukecarbis deleted the feature/rich-text branch June 18, 2019 09:12
@alancwoo
Copy link
Copy Markdown

alancwoo commented Aug 9, 2019

Is this block type only available in early access/pro? I just installed 1.3.4 and don't see this as an option.

@kienstra
Copy link
Copy Markdown
Collaborator

kienstra commented Aug 9, 2019

Hi @alancwoo, yes, the Rich Text field is only available in the Pro version.

lukecarbis added a commit to lukecarbis/block-lab that referenced this pull request Aug 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"WYSIWYG" control type

7 participants