EditorState

源码文件位置:src/model/immutable/EditorState.js
EditorState是什么呢?包含了哪些内容?
type EditorStateRecordType = { allowUndo: boolean, currentContent: ?ContentState, decorator: ?DraftDecoratorType, directionMap: ?OrderedMap[InvalidCharacterError: "STRING," did not match the Name production]
allowUndo: boolean,
是否允许撤销操作
currentContent: ?ContentState, decorator: ?DraftDecoratorType,

directionMap: ?OrderedMap[InvalidCharacterError: "STRING," did not match the Name production]

OrderedMap,表示每个block的文字方向。
directionMap: EditorBidiService.getDirectionMap(currentContent)
Q:directionMap是什么?有什么作用呢?以及应用场景?EditorBidiService是什么?
directionMap: {b70de: "LTR"}

forceSelection: boolean,

Q:强制render SelectionState指的是什么?这里的forceSelection是什么意思,有什么作用、应用场景?

inCompositionMode: boolean,

inCompositionMode是draftJs自动维护的,是依据DOM支持的事件:
onCompositionStart,onCompositionEnd,
  • compositionstart 中文输入法开始输入时触发,每次输入开始仅执行一次
  • compositonupdate 中文输入法在输入时触发,返回实时内容,例如zhong’wen,仅在 compositionstart 触发后触发,输入时实时触发多次
  • compositionend 复合系统关闭,返回正常键盘输入状态,中文输入法输入完成时触发,所得到的结果就是最终输入完成的结果,执行一次
src/component/base/DraftEditor.react.js, 在DraftEditor组件里面,div上确实绑定了
onCompositionEnd={this._onCompositionEnd} onCompositionStart={this._onCompositionStart}
用户是否在中文输入法或者其他组合输入法下面。作用是:以便用于呈现UI
比如是否展示Placeholder: (不是中文输入法,且没有文字时才展示。)
_showPlaceholder(): boolean { return ( !!this.props.placeholder && !this.props.editorState.isInCompositionMode() && !this.props.editorState.getCurrentContent().hasText() ); }
因为一开始输入中文时,如果你只打了部分拼音还没敲空格,hasText是false,
此时如果展示placeholder就有问题了。

inlineStyleOverride: ?DraftInlineStyle,

下一个插入的字符会被应用上的An inline style value,光标处于闪烁状态时(即collapsed,坍缩),会使用到它。
注:非坍缩时,选中一块区域再输入时,inline style取决于选区最开始时的字符的inline style。
lastChangeType: ?EditorChangeType,
nativelyRenderedContent: ?ContentState, redoStack: Stack, selection: ?SelectionState,

treeMap: ?OrderedMap[InvalidCharacterError: "STRING," did not match the Name production]

undoStack: Stack,
treeMap是什么?List中item的leaves是什么意思?
The fully decorated and styled tree of ranges to be rendered in the editor component.
treeMap: generateNewTreeMap(currentContent, decorator)
At render time, components should iterate through the treeMap object to render decorated ranges and styled ranges, using the getBlockTree() method.
getBlockTree(blockKey: string): List { return this.getImmutable().getIn(['treeMap', blockKey]); }
treeMap是OrderedMap类型
blockKey => List
List其实就是包含了,该block被截断成多个部分,每个被decorator range分割开的都是一个item,包括decorator range也是一个item
decoratorKey依次从 0.0 / 0.1 / 0.2 递增

EditorState.set()是实现原理是什么?

参考文献:
https://draftjs.org/docs/api-reference-editor-state