3
3
Component ,
4
4
Input ,
5
5
OnChanges ,
6
+ OnInit ,
6
7
output ,
7
8
SimpleChanges ,
8
9
} from '@angular/core' ;
@@ -86,15 +87,17 @@ export class BnaEditorComponent<
86
87
BSchema extends BlockSchema = DefaultBlockSchema ,
87
88
ISchema extends InlineContentSchema = DefaultInlineContentSchema ,
88
89
SSchema extends StyleSchema = DefaultStyleSchema
89
- > implements OnChanges
90
+ > implements OnChanges , OnInit
90
91
{
91
92
@Input ( )
92
93
options ?: BlockNoteEditorOptionsType < BSchema , ISchema , SSchema > ;
94
+
95
+ // TODO: move to reusable type
93
96
@Input ( )
94
- initialContent ! :
97
+ initialContent :
95
98
| Block < BSchema , ISchema , SSchema > [ ]
96
99
| PartialBlock < BSchema , ISchema , SSchema > [ ]
97
- | undefined ;
100
+ | undefined = undefined ;
98
101
99
102
contentChanged = output < Block < BSchema , ISchema , SSchema > [ ] > ( ) ;
100
103
selectedBlocks = output < Block < BSchema , ISchema , SSchema > [ ] > ( ) ;
@@ -108,14 +111,25 @@ export class BnaEditorComponent<
108
111
109
112
constructor ( private blockNoteAngularService : BlockNoteAngularService ) { }
110
113
114
+ ngOnInit ( ) {
115
+ this . createEditor ( this . initialContent ) ;
116
+ this . isInitialized = true ;
117
+ }
118
+
111
119
ngOnChanges ( changes : SimpleChanges ) {
112
120
if ( changes [ 'initialContent' ] ) {
121
+ // TODO: try to type the current value (currently any)
113
122
this . createEditor ( changes [ 'initialContent' ] . currentValue ) ;
114
123
this . isInitialized = true ;
115
124
}
116
125
}
117
126
118
- createEditor ( initialContent : Block < BSchema , ISchema , SSchema > [ ] ) {
127
+ createEditor (
128
+ initialContent :
129
+ | Block < BSchema , ISchema , SSchema > [ ]
130
+ | PartialBlock < BSchema , ISchema , SSchema > [ ]
131
+ | undefined
132
+ ) {
119
133
const schema = this . options ?. schema ;
120
134
this . editor = BlockNoteEditor . create ( {
121
135
trailingBlock : false ,
0 commit comments