1
- import { Component , OnInit , signal } from '@angular/core' ;
1
+ import { Component , signal } from '@angular/core' ;
2
2
import { FormControl , FormsModule , ReactiveFormsModule } from '@angular/forms' ;
3
3
import {
4
4
BlockFromConfig ,
@@ -30,7 +30,7 @@ import {
30
30
] ,
31
31
templateUrl : './bna-file-panel.component.html' ,
32
32
} )
33
- export class BnaFilePanelComponent implements OnInit {
33
+ export class BnaFilePanelComponent {
34
34
focusedBlock = signal < BlockFromConfig < FileBlockConfig , any , any > | undefined > (
35
35
undefined ,
36
36
) ;
@@ -40,20 +40,20 @@ export class BnaFilePanelComponent implements OnInit {
40
40
41
41
constructor ( private ngxBlockNoteService : NgxBlocknoteService ) {
42
42
const editor = this . ngxBlockNoteService . editor ( ) ;
43
- editor . filePanel ?. onUpdate ( async ( filePanelState ) => {
44
- if ( ! filePanelState . show ) {
45
- this . focusedBlock . set ( undefined ) ;
46
- } else {
47
- this . focusedBlock . set ( filePanelState . block ) ;
48
- }
49
- } ) ;
43
+ if ( editor . filePanel ) {
44
+ //TODO: remove the workaround
45
+ //Workaround use view state from file panel to get the block
46
+ this . focusedBlock . set ( ( editor . filePanel ! as any ) . view . state . block )
47
+ editor . filePanel . onUpdate ( async ( filePanelState ) => {
48
+ if ( ! filePanelState . show ) {
49
+ this . focusedBlock . set ( undefined ) ;
50
+ } else {
51
+ this . focusedBlock . set ( filePanelState . block ) ;
52
+ }
53
+ } ) ;
54
+ }
50
55
}
51
56
52
- ngOnInit ( ) {
53
- const editor = this . ngxBlockNoteService . editor ( ) ;
54
- const block = editor . getTextCursorPosition ( ) . block ;
55
- this . focusedBlock . set ( block as any ) ;
56
- }
57
57
58
58
async onFileInputChanged ( event : Event ) {
59
59
const editor = this . ngxBlockNoteService . editor ( ) ;
0 commit comments