-
Notifications
You must be signed in to change notification settings - Fork 2.6k
adding-support-for-paragraph - making blockTypes configurable #205
adding-support-for-paragraph - making blockTypes configurable #205
Conversation
…t module - Including paragraph on converter - Updating website and demo - Updating example
{label: 'H1', style: 'header-one'}, | ||
{label: 'H2', style: 'header-two'}, | ||
{label: 'H3', style: 'header-three'}, | ||
{label: 'H4', style: 'header-four'}, |
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.
added the extra missing headers from the rich example
cc @CLowbrow -- will it be a problem to have |
will let you guys decide, in the meantime i noticed some tests are broken fixing them now and amending the PR. Will move the missing headers from this PR to the other PR since it makes more sense in #207 then here |
…since it has been added on another pull request - Removed the inclusion of the extra headers from the rich.html since a new PR is dealing with it #207
@hellendag stuff broke with some renderers when we added the H4/5/6 stuff right? I'm worried the same stuff is going to happen here. Do our renderers know how to deal with this type? I'm half-remembering all of this, though. Right now 'unstyled' basically means paragraph. We can change it, but then what would unstyled be? Is it redundant? |
- When we used paragraph as an invalid element to generate unstyled swapped that to use div instead
@CLowbrow could unstyled mean divs ? I would imagine Divs to be the most generic block container. |
@@ -130,8 +130,8 @@ describe('DraftPasteProcessor', function() { | |||
}); | |||
|
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.
Updated 'p' to become 'div' since we were using 'p' with the assumption that would default to unstyled
|
(I guess we already have the reverse mapping though?) |
@spicy, I agree to some extent to that. Paragraphs can definitely be an annoyance. However they provide semantics and also makes a lot easier on moving to draftjs from existing applications. Another option would be to make this behaviour configurable. We could default to paragraphs being unstyled but however allow a configuration option to overwrite it to include them as a valid block type. |
The current behavior is a little complicated. We basically ignore divs in the html structure unless there are no semantic elements. HTML will often contain something like We apply unstyled tags to the content of Since, generally, we don't want to treat divs as meaningful tags, I don't think we need two types that mean text block. I might be missing something though. Can you provide an example of the case you are trying to solve for? |
One example is that if you currently copy and paste unsupported blocks it by default get's rendered as unstyled (which is currently used as paragraphs), which makes harder to export documents where we want to be able to correctly identify which elements where meant to be real paragraphs and which elements where just unsupported block elements. |
That makes sense. @hellendag I think this is taking us back to the "pass a map of block tag names to types" thing. I think the best solution is for this to be configurable with minimal defaults. Thoughts? |
I like the idea of being configurable, happy to amend the PR if you guys reckon that's the way to go |
Yeah, they did. It was my fault though, I didn't sanitize it properly.
Yep. I think this is the right thing to do. Configurable block mapping, inline style mapping, and link extraction. |
@hellendag @CLowbrow, been thinking through and I really see the benefits of having block mapping, inline styles and link extractions as a configurable configuration.
In order for this to work, I would suggest that configurations should be explicit overwrites, this would allow us to either have a large default configuration on draft-js or just a very simple basic one. My recommendation is keeping draft-js defaults for block mapping, inline style mapping very basic and instead move most of the advanced blocks and inline styles as configuration to the examples. What are your thoughts on it ? |
I definitely agree. Would you like to give it a try for this PR?
Yes. A sensible default is important and I think it makes sense to keep our existing mapping as that default. |
Sounds good, will amend this PR. The scope will be to make the current:
|
Just commenting in here to inform that this PR is not dead yet, working on the above decision. Since it involves major internal changes is taking a little longer, But will update this ASAP |
- Adding new DraftBlockMap type - Making blocks extensible - Exposing default blocks so that it can be used to be extended - Updating the rich example to use custom blocks by adding a paragraph - creating a new customBLockMap type - updating getElementForBlockType.js and getWrapperTemplateForBlockType to accept an optional DraftBlockMap to use intead of default - updating DraftPasteProcessor to accept custom blockmaps - updating tests - adding dev gulp task to speed up development when testing using one of the examples
@@ -89,6 +89,17 @@ | |||
} | |||
} | |||
|
|||
var customBlockMap = Object.assign({}, DefaultDraftBlock, { |
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.
Should I update this to use Immutable ?
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.
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.
Should I leave as it is then ?
lastLastBlock === 'br' && | ||
(!inBlock || getBlockTypeForTag(inBlock, lastList) === 'unstyled') | ||
lastLastBlock === 'br' && (!inBlock || | ||
getBlockTypeForTag(inBlock, lastList, draftBlockRenderMap) === 'unstyled') |
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.
Spacing nit, just a personal preference really:
if (
lastLastBlock === 'br' &&
(
!inBlock ||
getBlockTypeForTag(...) === 'unstyled'
)
) {
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 don't mind it, we should probably add this as a rule to eslintrc so that the formatting can be picked up on the linting
Nice! I think we're really close. :) |
- Removed modules getElementForBlockType and getWrapperTemplateForBlockType in favour of inlining behaviour - updated convertFromHTMLToContentBlocks.js to use getIn and also check for the DefaultBLockRender unstyled element in case none is provided since we apply them in that case - Fixed flow Error suppressing comment. Unused suppression - Fixed indent
- Updated the example file to use state and avoid multiple object creations during render
- Updating to use Immutable.getIn and removing extranous checks
var workingBlocks = containsSemanticBlockMarkup(html) ? blockTags : ['div']; | ||
var workingBlocks = containsSemanticBlockMarkup(html, supportedBlockTags) ? | ||
supportedBlockTags : | ||
['div']; |
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 wonder if the intention here would be to default to unstyled if so will also update it here
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 leave as it is for this PR to avoid any further change since it is already big enough
Ok, let's do this. :) |
@facebook-github-bot import |
awesome! |
Thanks for importing. If you are an FB employee go to Phabricator to review. |
@@ -11,6 +11,8 @@ | |||
|
|||
'use strict'; | |||
|
|||
const DefaultDraftBlockRenderMap = require('DefaultDraftBlockRenderMap'); |
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.
FYI the rest of the imports are alphabetical order.
Sorry for the long wait. :) This is in review internally, and we're being thorough to make sure it works cleanly. |
Okay, I'm going to land and merge this today. I've made quite a few changes, so let me know if you notice anything missing or incorrect. |
e203798
Hello @mitermayer : I am working on creating an editor using DraftJS and we were looking for something similar in supporting paragraph blocks. Thanks a lot for good work 👍 Can you please guild me where can I get documentation for passing configuration parameters to the editor. I could not find that in the commit. |
@jpuri Sorry for not including the documentation on this PR it will be bundled on a separate PR with example. In the meantime you can follow the reverse of this commit, 575e051 this had an example on how to integrate paragraph to the rich.html demo and also how to overwritte the default 'unstyled' to become a paragraph. |
Thanks a lot @mitermayer, but editor gives me this error with the configurations, should I just ignore it ? |
@jpuri Will talk via slack in order to reduce feedback loop and help debug whats the problem |
Thanks @mitermayer |
Attached the article documentation for it on the PR #387 |
Summary: This fixes issue facebookarchive#204 - Including paragraph on converter - Updating website and demo - Updating example Closes facebookarchive#205 Reviewed By: ezequiel Differential Revision: D3147267 fb-gh-sync-id: ae51df9b838597066a699dced879b2795e59db26 fbshipit-source-id: ae51df9b838597066a699dced879b2795e59db26
Summary: This fixes issue facebookarchive/draft-js#204 - Including paragraph on converter - Updating website and demo - Updating example Closes facebookarchive/draft-js#205 Reviewed By: ezequiel Differential Revision: D3147267 fb-gh-sync-id: ae51df9b838597066a699dced879b2795e59db26 fbshipit-source-id: ae51df9b838597066a699dced879b2795e59db26
Summary: This fixes issue facebookarchive/draft-js#204 - Including paragraph on converter - Updating website and demo - Updating example Closes facebookarchive/draft-js#205 Reviewed By: ezequiel Differential Revision: D3147267 fb-gh-sync-id: ae51df9b838597066a699dced879b2795e59db26 fbshipit-source-id: ae51df9b838597066a699dced879b2795e59db26
Summary: This fixes issue facebookarchive/draft-js#204 - Including paragraph on converter - Updating website and demo - Updating example Closes facebookarchive/draft-js#205 Reviewed By: ezequiel Differential Revision: D3147267 fb-gh-sync-id: ae51df9b838597066a699dced879b2795e59db26 fbshipit-source-id: ae51df9b838597066a699dced879b2795e59db26
This fixes issue #204