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

Ability to select which inline styles, block types, links should be retained on paste #1057

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

mkhazov
Copy link

@mkhazov mkhazov commented Mar 7, 2017

fixes #166

```
stripPastedStyles?: boolean
stripPastedStyles?: Object
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: this is still using the old new

export type DraftPasteSupport = {
inlineStyles: List<string>,
blockTypes: List<string>,
links: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're going to go this far, why not also allow images to be blocked?

stripPastedStyles?: boolean
stripPastedStyles?: Object
```
Optionally define which inline styles, block types and links should be retained on paste.
Copy link
Contributor

Choose a reason for hiding this comment

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

We should go into more depth here to make the documentation easier to use. For example, we should clarify that the supported block types is the intersection between those defined in the block render map and those defined in this structure. We should provide an example, non-empty, value for this field as well so that users don't need to spelunk through the source to find how each field is being interpreted and used.

@mkhazov
Copy link
Author

mkhazov commented Mar 9, 2017

@colinjeanne thanks, I've added ability to strip images and updated the docs.

@mkhazov mkhazov force-pushed the paste_support branch 2 times, most recently from 44edb5b to 211541e Compare October 27, 2017 15:15
Copy link
Contributor

@thibaudcolas thibaudcolas left a comment

Choose a reason for hiding this comment

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

I made a separate library that does the same thing as this PR, and thought I should mention a few other things that should IMHO be configurable in the paste support:

  • What amount of block nesting to preserve – If the editor only allows flat lists, then it shouldn't be possible to paste nested ones.
  • For entities (images/links), what data to keep – if I remember correctly, for links Draft.js will have both href and url with slightly different content, and images have width/height which are of no use in many cases.
  • For entities again, whether to keep them or not based on their data. For example, you might not want your editor to allow pasting images from Word (local file path), but might be ok with hotlinked images from your own website.

It would also make sense to allow to decide what entities to allow paste for beyond links/images if #787 gets fixed (see #1784).

For further reference (API, tests), the lib is /~https://github.com/thibaudcolas/draftjs-filters.

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.

Ability to select what inline styles to retain/strip in paste
5 participants