-
Notifications
You must be signed in to change notification settings - Fork 64
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
Process, whitelist, blacklist, migrate available blocks, styles and entities when pasting rich text #50
Conversation
3e36fd5
to
9b3a7bd
Compare
74e7acb
to
80ea9c3
Compare
9ec1f12
to
f5ab772
Compare
f5ab772
to
dcba485
Compare
@@ -15,7 +15,6 @@ The behavior of this editor is heavily inspired by prior art. If you want to dis | |||
* [ ] [Google Docs](https://docs.google.com/) | |||
* [ ] [Apple Pages](https://www.apple.com/lae/pages/) | |||
* [ ] [Dropbox Paper](https://www.dropbox.com/paper) | |||
* [ ] [Open Office Writer](https://www.openoffice.org/product/writer.html) |
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.
On second thought, I don't want to support this.
- mv webpack/webpack-stats.html public || true | ||
- mv coverage/lcov-report public || true |
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.
Unrelated.
docs/README.md
Outdated
|
||
Here are specific external sources we want to pay special attention too, and for which we have ready-made test documents with all of the possible rich content. | ||
|
||
* [ ] [Microsoft Word](https://products.office.com/en/word): TODO |
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.
TODO, urgently. I want to try this on Windows especially, and it will be easier once this is merged.
|
||
* https://github.com/springload/draftail/blob/df903f86c882bd5101eb05e152e8b8a8b9a4915e/lib/blocks/MediaBlock.js#L60-L71 | ||
* https://github.com/springload/draftail/commit/431c3fd09c4cfc043c8b334544b05b9f580b75d2 | ||
* https://github.com/springload/draftail/blob/df903f86c882bd5101eb05e152e8b8a8b9a4915e/lib/api/behavior.js#L100-L110 | ||
* https://github.com/springload/draftail/commit/8d9de77349cd2f7ee1cba36b03f2946a21039dde | ||
* https://github.com/springload/draftail/blob/df903f86c882bd5101eb05e152e8b8a8b9a4915e/lib/api/behavior.js#L23:L26 | ||
* https://github.com/springload/draftail/commit/162fc13e193ac581f662de393151efde477183b9 |
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.
Might add a few more once this is merged, because the paste behavior is very dependent on Draft.js internals right now.
<div data-mount-test></div> | ||
|
||
<hr> | ||
|
||
<h3>Copy/paste test cases</h3> |
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.
Might put this in a separate file in the future.
.filter(type => !enabledTypes.includes(type)) | ||
.forEach(type => { | ||
altered = true; | ||
newChar = CharacterMetadata.removeStyle(newChar, type); |
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.
Reducing over the array to create a char without any styles. There may be a simpler way, but I doubt there would be chars with more than say 10 inline styles in a worst case scenario. 2-3 is already a lot for real-world content.
block => | ||
block.getType() === BLOCK_TYPE.ATOMIC && | ||
(block.getText() !== ' ' || | ||
block.getInlineStyleAt(0).size !== 0), |
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.
Normalises the block if its text isn't right, or if it has inline styles on it. Happens with pasting from Google Docs.
const entityKey = block.getEntityAt(0); | ||
let shouldReset = false; | ||
|
||
if (entityKey) { |
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'm not sure how there could be an atomic block without an entity in real-world content, but we never know.
* on paste. | ||
* A better approach would probably be to split the block where the image is and | ||
* create an atomic block there, but that's another story. This is what Draft.js | ||
* does when the copy-paste is all within one editor. |
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.
This may not be that complicated with the Modifier
method that does this, but another time.
* that Draft.js inserts. | ||
* If we want to remove this in the future, consider that: | ||
* - It needs to be removed in the block text, where it's 2 chars / 1 code point. | ||
* - The corresponding CharacterMetadata needs to be removed too, and it's 2 instances |
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.
Unicode fun.
Very WIP.