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