Skip to content
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

Merged
merged 27 commits into from
Dec 3, 2017

Conversation

thibaudcolas
Copy link
Collaborator

Very WIP.

@thibaudcolas thibaudcolas added the enhancement New feature or request label Mar 10, 2017
@coveralls
Copy link

coveralls commented Mar 10, 2017

Coverage Status

Coverage increased (+0.2%) to 56.543% when pulling e2feca2 on feature/rich-paste-filtering into fa88c74 on master.

@coveralls
Copy link

coveralls commented Mar 10, 2017

Coverage Status

Coverage increased (+0.2%) to 56.543% when pulling 3e36fd5 on feature/rich-paste-filtering into 3641d6f on master.

@thibaudcolas thibaudcolas force-pushed the feature/rich-paste-filtering branch from 3e36fd5 to 9b3a7bd Compare May 25, 2017 15:45
@thibaudcolas thibaudcolas force-pushed the feature/rich-paste-filtering branch 2 times, most recently from 74e7acb to 80ea9c3 Compare October 18, 2017 08:03
@thibaudcolas thibaudcolas mentioned this pull request Oct 18, 2017
10 tasks
@thibaudcolas thibaudcolas force-pushed the feature/rich-paste-filtering branch 2 times, most recently from 9ec1f12 to f5ab772 Compare December 2, 2017 13:48
@thibaudcolas thibaudcolas force-pushed the feature/rich-paste-filtering branch from f5ab772 to dcba485 Compare December 3, 2017 17:09
@thibaudcolas thibaudcolas changed the title [WIP] Filter available blocks, styles and entities when pasting rich text Filter available blocks, styles and entities when pasting rich text Dec 3, 2017
@thibaudcolas thibaudcolas changed the title Filter available blocks, styles and entities when pasting rich text Process, whitelist, blacklist, migrate available blocks, styles and entities when pasting rich text Dec 3, 2017
@thibaudcolas thibaudcolas added this to the Wagtail 2.0 milestone Dec 3, 2017
@thibaudcolas thibaudcolas self-assigned this Dec 3, 2017
@@ -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)
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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>
Copy link
Collaborator Author

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);
Copy link
Collaborator Author

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),
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

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.
Copy link
Collaborator Author

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
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unicode fun.

@thibaudcolas thibaudcolas merged commit 8361d48 into master Dec 3, 2017
@thibaudcolas thibaudcolas deleted the feature/rich-paste-filtering branch December 3, 2017 20:26
@springload springload deleted a comment from deborahharrus Dec 3, 2017
@thibaudcolas thibaudcolas mentioned this pull request Dec 4, 2017
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants