1. SelectionState
interface SelectionState {
anchorKey: string;
anchorOffset: number;
focusKey: string;
focusOffset: number;
hasFocus: boolean;
isBackward: boolean;
getStartKey: () => string;
getStartOffset: () => number;
getEndKey: () => string;
getEndOffset: () => number;
isCollapsed: () => boolean;
hasEdgeWithin: (blockKey: string, start: number, end: number) => boolean;
}
2. EditorChangeType
type EditorChangeType =
| 'adjust-depth'
| 'apply-entity'
| 'backspace-character'
| 'change-block-data'
| 'change-block-type'
| 'change-inline-style'
| 'move-block'
| 'delete-character'
| 'insert-characters'
| 'insert-fragment'
| 'redo'
| 'remove-range'
| 'spellcheck-change'
| 'split-block'
| 'undo';
3. EditorState
type BaseEditorStateConfig = {
allowUndo?: boolean,
decorator?: ?DraftDecoratorType,
directionMap?: ?OrderedMap<string, string>,
forceSelection?: boolean,
inCompositionMode?: boolean,
inlineStyleOverride?: ?DraftInlineStyle,
lastChangeType?: ?EditorChangeType,
nativelyRenderedContent?: ?ContentState,
redoStack?: Stack<ContentState>,
selection?: ?SelectionState,
treeMap?: ?OrderedMap<string, List<any>>,
undoStack?: Stack<ContentState>,
}
interface EditorState {
static createEmpty(decorator?: DraftDecoratorType): EditorState;
static createWithText(text: string, decorator?: DraftDecoratorType): EditorState;
static createWithContent(contentState: ContentState, decorator?: DraftDecoratorType): EditorState;
static create(config: {
...BaseEditorStateConfig,
currentContent: ContentState
}): EditorState;
toJS(): Object;
getCurrentContent(): ContentState;
getUndoStack(): Stack<ContentState>;
getLastChangeType(): ?EditorChangeType;
getCurrentInlineStyle(): DraftInlineStyle;
static setInlineStyleOverride(
editorState: EditorState,
inlineStyleOverride: DraftInlineStyle,
);
static acceptSelection(
editorState: EditorState;
selection: SelectionState;
): EditorState;
static forceSelection(
editorState: EditorState,
selection: SelectionState,
): EditorState;
static moveSelectionToEnd(editorState: EditorState): EditorState;
static moveFocusToEnd(editorState: EditorState): EditorState;
static set(
editorState: EditorState,
put: {
...BaseEditorStateConfig,
currentContent?: ContentState}
},
): EditorState;
static push(
editorState: EditorState,
contentState: ContentState,
changeType: EditorChangeType,
forceSelection: boolean = true,
): EditorState;
}
4. ContentState
interface ContentState {
static createFromText(
text: string,
delimiter?: string | RegExp = /\r\n?|\n/g,
): ContentState;
static createFromBlockArray(
blocks: Array<BlockNodeRecord> | {contentBlocks: Array<BlockNodeRecord>, ...},
entityMap: ?any,
): ContentState;
static fromJS(state: ContentStateRawType): ContentState;
getSelectionBefore(): SelectionState;
getSelectionAfter(): SelectionState
createEntity(
type: DraftEntityType,
mutability: DraftEntityMutability,
data?: Object,
): ContentState;
getAllEntities(): OrderedMap<string, DraftEntityInstance>;
mergeEntityData(
entityKey: string,
toMerge: {[key: string]: any, ...},
): ContentState;
replaceEntityData(
key: string,
newData: interface {[key: string]: any},
): ContentState
getKeyBefore(key: string): ?string;
getBlockBefore(key: string): ?BlockNodeRecord;
getBlocksAsArray(): Array<BlockNodeRecord>;
getFirstBlock(): BlockNodeRecord;
getLastBlock(): BlockNodeRecord;
getPlainText(delimiter?: string): string;