Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

adding-support-for-paragraph - making blockTypes configurable #205

Closed
wants to merge 13 commits into from
Closed

adding-support-for-paragraph - making blockTypes configurable #205

wants to merge 13 commits into from

Conversation

mitermayer
Copy link
Contributor

This fixes issue #204

  • Including paragraph on converter
  • Updating website and demo
  • Updating example

…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'},
Copy link
Contributor Author

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

@hellendag
Copy link

cc @CLowbrow -- will it be a problem to have p map to paragraph in the paste processor?

@mitermayer
Copy link
Contributor Author

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
@CLowbrow
Copy link
Contributor

@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
@mitermayer
Copy link
Contributor Author

@CLowbrow could unstyled mean divs ? I would imagine Divs to be the most generic block container.

@@ -130,8 +130,8 @@ describe('DraftPasteProcessor', function() {
});

Copy link
Contributor Author

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

@sophiebits
Copy link
Contributor

p tags tend to be pretty annoying since browsers don't let you put any block-level tags (ex: div) inside of them. I've sworn off using <p> tags whenever I have a choice (opting instead for <div class="paragraph"> or similar) and recommend others do too. Is there a reason that they're necessary here?

@sophiebits
Copy link
Contributor

(I guess we already have the reverse mapping though?)

@mitermayer
Copy link
Contributor Author

@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.

@CLowbrow
Copy link
Contributor

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 <div><blockquote> hi </blockquote></div> and since we are flattening the tree we want to use the most important element in that case.

We apply unstyled tags to the content of <p> tags and to blocks that don't have any of the tags we look for. For example <h1> hello </h1> text <h2> goodbye</h2> and <h1> hello </h1> text <h2> goodbye</h2> and <h1> hello </h1><p> text <p><h2> goodbye</h2> and <div><h1> hello </h1><div> text <h2> goodbye</h2> will all generate the same block structure.

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?

@mitermayer
Copy link
Contributor Author

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.

@CLowbrow
Copy link
Contributor

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?

@mitermayer
Copy link
Contributor Author

I like the idea of being configurable, happy to amend the PR if you guys reckon that's the way to go

@hellendag
Copy link

@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.

Yeah, they did. It was my fault though, I didn't sanitize it properly. paragraph is a bit more worrying to me, though, since we really just don't even use that type.

@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?

Yep. I think this is the right thing to do. Configurable block mapping, inline style mapping, and link extraction.

@mitermayer
Copy link
Contributor Author

@hellendag @CLowbrow, been thinking through and I really see the benefits of having block mapping, inline styles and link extractions as a configurable configuration.

  1. Would allow consumers to create their custom block maps and would allow draft-js to not have to maintain new blocks and styles, would help on avoiding library bloating.
  2. Would also make upgrades a lot less risky, since there would be no surprises, as each consumer would know exactly which styles and block elements they support based on their configuration setting.

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 ?

@hellendag
Copy link

I definitely agree. Would you like to give it a try for this PR?

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.

Yes. A sensible default is important and I think it makes sense to keep our existing mapping as that default.

@mitermayer
Copy link
Contributor Author

Sounds good, will amend this PR. The scope will be to make the current:

  • Make it configurable settings
  • Make the current settings the default settings
  • Add tests and update documentation
  • Update an example or create a new one to use configuration settings.

@mitermayer
Copy link
Contributor Author

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, {
Copy link
Contributor Author

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 ?

Choose a reason for hiding this comment

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

There is an issue open for this: #52. @sstur is going to take a crack at it.

Edit: Oh wait, I should read the changeset more thoroughly. That issue applies to inline styles.

Copy link
Contributor Author

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')

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'
  )
) {

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 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

@hellendag
Copy link

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'];
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 wonder if the intention here would be to default to unstyled if so will also update it here

Copy link
Contributor Author

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

@hellendag
Copy link

Ok, let's do this. :)

@hellendag
Copy link

@facebook-github-bot import

@mitermayer
Copy link
Contributor Author

awesome!

@facebook-github-bot
Copy link

Thanks for importing. If you are an FB employee go to Phabricator to review.

@@ -11,6 +11,8 @@

'use strict';

const DefaultDraftBlockRenderMap = require('DefaultDraftBlockRenderMap');
Copy link
Contributor

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.

@hellendag
Copy link

Sorry for the long wait. :) This is in review internally, and we're being thorough to make sure it works cleanly.

@hellendag
Copy link

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.

@ghost ghost closed this in e203798 May 1, 2016
@jpuri
Copy link

jpuri commented May 4, 2016

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.

@mitermayer
Copy link
Contributor Author

@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.

@jpuri
Copy link

jpuri commented May 12, 2016

Thanks a lot @mitermayer, but editor gives me this error with the configurations, should I just ignore it ?

screen shot 2016-05-12 at 11 58 03 am

@mitermayer
Copy link
Contributor Author

@jpuri Will talk via slack in order to reduce feedback loop and help debug whats the problem

@jpuri
Copy link

jpuri commented May 12, 2016

Thanks @mitermayer

@mitermayer
Copy link
Contributor Author

Attached the article documentation for it on the PR #387

qgerome pushed a commit to whatever-company/draft-js that referenced this pull request Jun 9, 2016
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
midas19910709 added a commit to midas19910709/draft-js that referenced this pull request Mar 30, 2022
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
alicayan008 pushed a commit to alicayan008/draft-js that referenced this pull request Jul 4, 2023
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
aforismesen added a commit to aforismesen/draft-js that referenced this pull request Jul 12, 2024
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 pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants