ContentStateis an Immutable Record that represents the full state of:
- The entire contents of an editor: text, block and inline styles, and entity ranges.
- Two selection states of an editor: before and after the rendering of these contents.
The most common use for the
ContentStateobject is viaEditorState.getCurrentContent(), which provides theContentStatecurrently being rendered in the editor.An
EditorStateobject maintains undo and redo stacks comprised ofContentStateobjects.
ContentState是一个代表着全部状态的不可变记录对象:
- 编辑器的全部内容:文本、块和内联样式以及实体范围。
- 编辑器的两个选择状态:渲染这些内容之前和之后。
对于ContentState对象,最常见的用法是通过EditorState.getCurrentContent(),它提供了当前在编辑器被渲染的ContentState.
EditorState对象维护由ContentState对象组成的撤销和重做堆栈。
Overview
Static Methods
createFromText()
static createFromText(text: string,delimiter?: string): ContentState
Generates a
ContentStatefrom a string, with a delimiter to split the string intoContentBlockobjects. If no delimiter is provided, ‘\n‘ is used.
从一个字符串生成一个ContentState,用一个分隔符将字符串分割成ContentBlock对象。如果没有提供分隔符,则默认使用'\n'。
createFromBlockArray()
static createFromBlockArray(blocks: Array<ContentBlock>,entityMap: ?OrderedMap): ContentState
Generates a
ContentStatefrom an array ofContentBlockobjects. The defaultselectionBeforeandselectionAfterstates have the cursor at the start of the content.
从一个ContentBlock对象数组中生成一个ContentState。默认的selectionBefore和selectionAfter状态将光标放在内容的开头。
Methods
getEntityMap()
getEntityMap(): EntityMap
Returns an object store containing all
DraftEntityrecords that have been created. In upcoming v0.11.0 the map returned will be an Immutable ordered map ofDraftEntityrecords.
返回一个对象store,其中包含已创建的所有DraftEntity记录。在即将到来的v0.11.0中,返回的映射将是一个不可变的、有序的DraftEntity记录映射。
In most cases, you should be able to use the convenience methods below to target specific
DraftEntityrecords or obtain information about the state of the content.
在大多数情况下,您应该能够使用下面的便利方法来针对特定的DraftEntity记录或获取关于内容状态的信息。
getBlockMap()
getBlockMap(): BlockMap
Returns the full ordered map of
ContentBlockobjects representing the state of an entire document.
返回表示代表整个文档状态的ContentBlock对象的完整有序映射。
In most cases, you should be able to use the convenience methods below to target specific
ContentBlockobjects or obtain information about the state of the content.
在大多数情况下,您应该能够使用下面的便利方法来针对特定的ContentBlock对象或获取关于内容状态的信息。
getSelectionBefore()
getSelectionBefore(): SelectionState
Returns the
SelectionStatedisplayed in the editor before renderingblockMap.
