-
Notifications
You must be signed in to change notification settings - Fork 32
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
Outline RFC 46: Single paragraph rich text fields/blocks #46
Conversation
a7f6cbb
to
49d61a4
Compare
49d61a4
to
cfb0a37
Compare
@kaedroho could this be solved with a keyword parameter |
cfb0a37
to
5123d0e
Compare
This field would have a different internal representation and also be rendered differently on the frontend, so I think it would be best for it to be a different field type. Also, having a separate type would allow us to add APIs that are useful for segments alone, such as converting them to plain text or diffing them. There would also be no need to manually configure rich text features to limit them to inline elements only (I've noticed developers use |
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.
👍 nice, simple RFC. I think this would be very valuable, and as you say should be straightforward to implement.
I’ve made a prototype for this with Draftail a few months ago, https://demo.draftail.org/storybook/?path=/story/plugins--single-line. It:
- Disables block formatting and block-level entities (images, embeds)
- Disables pressing "Enter" to create a new block
- Has a check to automatically concatenate the content to a single line if the user finds a way to enter multiline content (e.g. copy-pasting rich text)
Does anyone know what the status of this RFC is? I’m interested in implementing this for a client who needs italics in headings, but it looks like it might be possible for me to implement it straight in Wagtail core. |
Here is my work-in-progress implementation if anyone wants to take a look: wagtail/wagtail#7249. |
New idea I've been thinking about that we could do in addition to this A subclass of For example: from wagtail.blocks import StoryBlock
class MyStoryBlock(StoryBlock):
# heading/paragraph block types are inherited
image = ImageBlock() The advantage of doing it this way is we can customise the display and behaviour of paragraphs/headings in the editor at the stream level rather than the individual blocks. This would allow us to display consecutive paragraph blocks one single rich text field, but save them as separate blocks. Advantages of this include:
The definition of this new block type inside Wagtail could be like so: class HeadingBlock(StructBlock):
text = ParagraphBlock()
level = NumberBlock()
id = CharBlock(required=False)
class ListItemBlock(StructBlock):
content = ParagraphBlock()
indent_level = NumberBlock()
class StoryBlock(StreamBlock):
heading = HeadingBlock()
paragraph = ParagraphBlock()
ordered_list_item = ListItemBlock()
unordered_list_item = ListItemBlock()
js_component = 'StoryBlock' # It would have it's own JS component What do you think? |
I’ve advanced this RFC one step in its lifecycle now that we’re making plans to implement this as part of the page editor 2022 project. I don’t feel competent to provide feedback on Karl’s comment above so would appreciate others stepping in. For my WIP implementation at wagtail/wagtail#7249 – I still think it’s relevant, although we’re going to be making changes to Draftail directly, as part of which I’d be keen for single-line editing to become a built-in feature of the editor. |
My general thoughts
|
Thank you for the feedback @lb-! To reply to your points:
|
I have now moved this RFC to |
@kaedroho @jacobtoppm just want to check if you intend to review this further / comment or if you think this is good to go as-is? |
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.
Looks good to me! I think I'm happy with what's been proposed so far. Just a note that for implementation, we'll need to make sure (if we're not persisting the Draftail block ids, as currently inline comment positions store the block id and the offsets) the comment positions are stored and retrieved relative to the start of the field instead if this option is turned on in CommentableEditor
. Not a big deal, just thought I'd mention it!
👍 thank you! Right now my implementation tasks are here: wagtail/wagtail#8249. The assumption is that Both of those are quite high-level plans, feel free to add :) |
Draft.js has confirmed that it is no longer maintained. The project will no longer receive updates and the GitHub repo will be archived in October of this year (October 2022). I think we need to consider this if we are to adopt our wrapper around Draft.js in even more places in Wagtail. Personally I don't think it's a blocker for this specific RFC but it needs to be a consideration in our long term planning and in how we try to allocate efforts. For example, should we start the journey of changing the underlying library of Draftail instead of focusing on making Draftail have different features. Sorry to be a pain with pointing these things out, it's just that a rich text field is far from simple and we want to try to build on something solid (well... As solid as we can get in the npm ecosystem). facebookarchive/draft-js#3091 (comment) |
@lb- this is definitely worth being aware of but I don’t think it affects this specific RFC. The RFC itself should be relevant regardless of whichever editor widget ends up supporting it, and the majority of the work needed will be for Wagtail to have this as a new field type. If we look at the implementation plan (wagtail/wagtail#8248, wagtail/wagtail#8249), about 1/3 of the work is specific to Draftail (and that’s the things I’ve already done as a POC so just need more testing / a better implementation). The remaining 2/3 are about the new field type. There’s been plenty of validation of this RFC to date so I’ll now merge this and we can proceed with the implementation. |
100% agree Thibaud. Thanks for replying, thanks for the amazing work along the way (and yet to do) on this. |
Rendered
This is an outline proposal for a new field and block type which would behave like a
RichTextField
/RichTextBlock
but only allows a single segment of text.Inline elements such as formatting and hyperlinks may be allowed. But block elements like paragraphs, images and bullet points will not. The HTML segment in the database will not be enclosed in a
<p>
tag giving developers more flexibility in where it can be used.I think this will be very useful for:
We should create a separate type to represent the values of these fields. Having a separate type rather than reusing
RichText
would be useful because logic, like diffing and translating, would work very differently when working with individual segments.