-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Plugin: Add Heading Block #337
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside the default as h2
, this LGTM 👍 for a v1 of the heading block.
Now, we have some work to do on the Editable
side to ensure we can not create paragraphs etc... (but this is transversal to different blocks, same for text
for example)
editor/blocks/heading-block/index.js
Outdated
}, | ||
|
||
edit( attributes, onChange ) { | ||
const { headingType = 'H1', value } = attributes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use h2
by default to keep h1
for the post title.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
editor/blocks/index.js
Outdated
@@ -1 +1,2 @@ | |||
import './text-block'; | |||
import './heading-block'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could drop the -block
suffix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
editor/blocks/heading-block/index.js
Outdated
|
||
save( attributes ) { | ||
const { headingType = 'H1', value } = attributes; | ||
return <Heading nodeName={ headingType }>{ value }</Heading>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not type={ headingType }
as the prop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I went back and forth on that. Technically the value for the property is the nodeName
and not the tag
value. So I left it as nodeName
. I basically just copied what aduth wrote because it looked good lol.
62a40be
to
570b744
Compare
We will need some way to change the |
I think we should try to have |
@iseulde Sounds like a potentially better solution. From my understanding, that would mean not using TinyMCE for the heading block? What will we lose out on if we use
instead? |
Hey, Have you considered making tinymce use the heading itself as the target container, rather than embedding a div inside the heading? I see at the moment that the Editable react component always creates a div and uses that as the rendered element, but you could make its node name configurable. Then you wouldn't have to worry about If you want an example of using a heading tag for an inline tinymce instance, see the examples here: https://www.tinymce.com/docs/demo/inline/ |
@ephox-mogran What are the pros of this approach compared to always using a |
It gives tinymce more context for the various operations. With differently structured blocks (like ol and ul), it prevents the insertion of a div tag from causing problems with the HTML structure. Primarily, it means that tinymce is given more information to make decisions, and more of the finer formatting details can be delegated to tiny. When a tinymce instance is created on a target node, it's able to use that node to govern how it should act (with regards to Enter key behaviour etc). If you are embedding tinymce inside something and then trying to give tinymce restrictions based on information that you know but it doesn't, it's probably going to get a lot more complicated. |
@ephox-mogran Thanks for the explanation, Good points here. I guess the more we build blocks (heading, quotes, lists, text ...), the more we'll have context on whether we should do this or not. (Especially when we'll introduce keyboard interactions and HTML restrictions) |
See #327 (comment) for relevant changes to |
Closing in favor of #423 |
Accidentally made a mess of git here is a clean version adding in JSX and making use of t he Editable component.