Filter Draft.js content when copy-pasting rich text into the editor. Initially made for Draftail.
Check out the online demo.
Using the filters
First, grab the package from npm:
npm install --save draftjs-filters
WIP – Then, import the filters' entry point and use it in your <Editor>
's onChange
function:
import { filterEditorState } from "draftjs-filters"
function onChange(nextEditorState) {
const {
stateSaveInterval,
maxListNesting,
enableHorizontalRule,
stripPastedStyles,
blockTypes,
inlineStyles,
entityTypes,
} = this.props
const { editorState } = this.state
const content = editorState.getCurrentContent()
const nextContent = nextEditorState.getCurrentContent()
const shouldFilterPaste =
nextContent !== content &&
!stripPastedStyles &&
nextEditorState.getLastChangeType() === "insert-fragment"
let filteredEditorState = nextEditorState
if (shouldFilterPaste) {
filteredEditorState = filterEditorState(
nextEditorState,
maxListNesting,
enableHorizontalRule,
blockTypes,
inlineStyles,
entityTypes,
)
}
this.setState({ editorState: filteredEditorState })
}
Browser support and polyfills
The Draft.js filters follow the browser support targets of Draft.js. Be sure to have a look at the Draft.js required polyfills.
Contributing
See anything you like in here? Anything missing? We welcome all support, whether on bug reports, feature requests, code, design, reviews, tests, documentation, and more. Please have a look at our contribution guidelines.
Development
Install
Clone the project on your computer, and install Node. This project also uses nvm.
nvm install
npm install
./.githooks/deploy
Working on the project
Everything mentioned in the installation process should already be done.
nvm use
npm run start
npm run lint
npm run flow
npm run format
npm run test:watch
npm run test:coverage
npm run report:coverage
npm run report:build
npm run
Releases
Credits
View the full list of contributors. MIT licensed. Website content available as CC0.