@@ -27,6 +27,36 @@ const Immutable = require('immutable');
27
27
28
28
const { OrderedSet, Record, Stack} = Immutable ;
29
29
30
+ // When configuring an editor, the user can chose to provide or not provide
31
+ // basically all keys. `currentContent` varies, so this type doesn't include it.
32
+ // (See the types defined below.)
33
+ type BaseEditorStateConfig = { |
34
+ allowUndo ? : boolean ,
35
+ decorator ?: ?DraftDecoratorType ,
36
+ directionMap ?: ?OrderedMap < string , string > ,
37
+ forceSelection ?: boolean ,
38
+ inCompositionMode ? : boolean ,
39
+ inlineStyleOverride ?: ?DraftInlineStyle ,
40
+ lastChangeType ?: ?EditorChangeType ,
41
+ nativelyRenderedContent ?: ?ContentState ,
42
+ redoStack ?: Stack < ContentState > ,
43
+ selection ?: ?SelectionState ,
44
+ treeMap ?: ?OrderedMap < string , List < any >> ,
45
+ undoStack ?: Stack < ContentState > ,
46
+ | } ;
47
+
48
+ // When crating an editor, we want currentContent to be set.
49
+ type EditorStateCreationConfigType = { |
50
+ ...BaseEditorStateConfig ,
51
+ currentContent : ContentState ,
52
+ | } ;
53
+
54
+ // When using EditorState.set(...), currentContent is optional
55
+ type EditorStateChangeConfigType = { |
56
+ ...BaseEditorStateConfig ,
57
+ currentContent ?: ?ContentState ,
58
+ | } ;
59
+
30
60
type EditorStateRecordType = {
31
61
allowUndo : boolean ,
32
62
currentContent : ?ContentState ,
@@ -41,7 +71,6 @@ type EditorStateRecordType = {
41
71
selection : ?SelectionState ,
42
72
treeMap : ?OrderedMap < string , List< any >> ,
43
73
undoStack : Stack < ContentState > ,
44
- ...
45
74
} ;
46
75
47
76
const defaultRecord : EditorStateRecordType = {
@@ -92,7 +121,7 @@ class EditorState {
92
121
} ) ;
93
122
}
94
123
95
- static create ( config : Object ) : EditorState {
124
+ static create ( config : EditorStateCreationConfigType ) : EditorState {
96
125
const { currentContent, decorator} = config ;
97
126
const recordConfig = {
98
127
...config ,
@@ -102,7 +131,10 @@ class EditorState {
102
131
return new EditorState ( new EditorStateRecord ( recordConfig ) ) ;
103
132
}
104
133
105
- static set ( editorState : EditorState , put : Object ) : EditorState {
134
+ static set (
135
+ editorState : EditorState ,
136
+ put : EditorStateChangeConfigType ,
137
+ ) : EditorState {
106
138
const map = editorState . getImmutable ( ) . withMutations ( state => {
107
139
const existingDecorator = state . get ( 'decorator' ) ;
108
140
let decorator = existingDecorator ;
@@ -115,7 +147,7 @@ class EditorState {
115
147
const newContent = put . currentContent || editorState . getCurrentContent ( ) ;
116
148
117
149
if ( decorator !== existingDecorator ) {
118
- const treeMap : OrderedMap < any , any > = state . get ( 'treeMap' ) ;
150
+ const treeMap : OrderedMap < string , any > = state . get ( 'treeMap' ) ;
119
151
let newTreeMap ;
120
152
if ( decorator && existingDecorator ) {
121
153
newTreeMap = regenerateTreeForNewDecorator (
0 commit comments