package
Collection of utilities to make code blocks edition easy in DraftJS
npm install draft-js-codeGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
draft-js-code is a collection of low-level utilities to make code block editing in DraftJS editors nicer.
It works well with draft-js-prism or draft-js-prism-plugin.
Demo: samypesse.github.io/draft-js-code/
(), [], {}, "", etc. (#3)$ npm install draft-js-code --saveCodeUtils.hasSelectionInBlock(editorState)Returns true if user is editing a code block. You should call this method to encapsulate all other methods when limiting code edition behaviour to code-block.
CodeUtils.handleKeyCommand(editorState, command)Handle key command for code blocks, returns a new EditorState or null.
CodeUtils.onTab(e, editorState)Handle user pressing tab, to insert indentation, it returns a new EditorState.
CodeUtils.handleReturn(e, editorState)Handle user pressing return, to insert a new line inside the code block, it returns a new EditorState.
import React from 'react';
import Draft from 'draft-js';
import CodeUtils from 'draft-js-code';
class Editor extends React.Component {
constructor(props) {
super(props);
this.state = {
editorState: Draft.EditorState.createEmpty()
};
}
onChange = (editorState) => {
this.setState({
editorState
})
}
handleKeyCommand = (command) => {
Estimated unpacked size across 5 packages.
734.2 kB
Includes dependencies.
samypesse
samypesse@gmail.com
3.x
5.2.1
^4.0.0
7.0.2
^2.1.0
4.0.1