Skip to content

Commit 32b327a

Browse files
committed
feat: make initialContent optional
refs #4131
1 parent c907e38 commit 32b327a

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

libs/block-note-angular/src/lib/block-note-editor/bna-editor.component.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Component,
44
Input,
55
OnChanges,
6+
OnInit,
67
output,
78
SimpleChanges,
89
} from '@angular/core';
@@ -86,15 +87,17 @@ export class BnaEditorComponent<
8687
BSchema extends BlockSchema = DefaultBlockSchema,
8788
ISchema extends InlineContentSchema = DefaultInlineContentSchema,
8889
SSchema extends StyleSchema = DefaultStyleSchema
89-
> implements OnChanges
90+
> implements OnChanges, OnInit
9091
{
9192
@Input()
9293
options?: BlockNoteEditorOptionsType<BSchema, ISchema, SSchema>;
94+
95+
// TODO: move to reusable type
9396
@Input()
94-
initialContent!:
97+
initialContent:
9598
| Block<BSchema, ISchema, SSchema>[]
9699
| PartialBlock<BSchema, ISchema, SSchema>[]
97-
| undefined;
100+
| undefined = undefined;
98101

99102
contentChanged = output<Block<BSchema, ISchema, SSchema>[]>();
100103
selectedBlocks = output<Block<BSchema, ISchema, SSchema>[]>();
@@ -108,14 +111,25 @@ export class BnaEditorComponent<
108111

109112
constructor(private blockNoteAngularService: BlockNoteAngularService) {}
110113

114+
ngOnInit() {
115+
this.createEditor(this.initialContent);
116+
this.isInitialized = true;
117+
}
118+
111119
ngOnChanges(changes: SimpleChanges) {
112120
if (changes['initialContent']) {
121+
// TODO: try to type the current value (currently any)
113122
this.createEditor(changes['initialContent'].currentValue);
114123
this.isInitialized = true;
115124
}
116125
}
117126

118-
createEditor(initialContent: Block<BSchema, ISchema, SSchema>[]) {
127+
createEditor(
128+
initialContent:
129+
| Block<BSchema, ISchema, SSchema>[]
130+
| PartialBlock<BSchema, ISchema, SSchema>[]
131+
| undefined
132+
) {
119133
const schema = this.options?.schema;
120134
this.editor = BlockNoteEditor.create({
121135
trailingBlock: false,

0 commit comments

Comments
 (0)