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
| * [ ] [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.
On second thought, I don't want to support this.
| - npm run test:ci | ||
| # Move build artefacts to public folder so they are published on the demo site. | ||
| - mv webpack/webpack-stats.html public || true | ||
| - mv coverage/lcov-report public || true |
|
|
||
| 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.
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/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.
Might add a few more once this is merged, because the paste behavior is very dependent on Draft.js internals right now.
|
|
||
| <hr> | ||
|
|
||
| <h3>Copy/paste test cases</h3> |
There was a problem hiding this comment.
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.
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.
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.
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.
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 |
Very WIP.