1
1
import {
2
2
Component ,
3
- Directive ,
4
3
ElementRef ,
5
4
input ,
6
5
OnChanges ,
7
- Renderer2
6
+ Renderer2 ,
8
7
} from '@angular/core' ;
8
+ import { FormsModule } from '@angular/forms' ;
9
9
import {
10
10
BlockFromConfig ,
11
11
BlockNoteEditor ,
12
- FileBlockConfig
12
+ FileBlockConfig ,
13
13
} from '@blocknote/core' ;
14
- import { autoUpdate , computePosition , flip } from '@floating-ui/dom' ;
15
- import { getVirtualElement } from '../../util/get-virtual-element.util ' ;
14
+ import { autoUpdate , computePosition , flip , offset } from '@floating-ui/dom' ;
15
+ import { HlmButtonDirective } from '@spartan-ng/ui-button-helm ' ;
16
16
import { HlmInputDirective } from '@spartan-ng/ui-input-helm' ;
17
17
import {
18
18
HlmTabsComponent ,
19
- HlmTabsListComponent
19
+ HlmTabsContentDirective ,
20
+ HlmTabsListComponent ,
21
+ HlmTabsTriggerDirective ,
20
22
} from '@spartan-ng/ui-tabs-helm' ;
21
- import { HlmButtonDirective } from '@spartan-ng/ui-button-helm' ;
22
- import { FormsModule } from '@angular/forms' ;
23
+ import { getVirtualElement } from '../../util/get-virtual-element.util' ;
23
24
24
25
@Component ( {
25
26
selector : 'bna-file-panel' ,
@@ -29,12 +30,14 @@ import { FormsModule } from '@angular/forms';
29
30
HlmTabsComponent ,
30
31
HlmTabsListComponent ,
31
32
HlmButtonDirective ,
32
- FormsModule
33
+ FormsModule ,
34
+ HlmTabsTriggerDirective ,
35
+ HlmTabsContentDirective ,
33
36
] ,
34
37
templateUrl : './bna-file-panel.component.html' ,
35
38
} )
36
39
export class BnaFilePanelComponent implements OnChanges {
37
- editor = input . required < BlockNoteEditor < any , any , any > > ( ) ;
40
+ editor = input . required < BlockNoteEditor < any , any , any > > ( ) ;
38
41
private block ?: BlockFromConfig < FileBlockConfig , any , any > ;
39
42
40
43
embedInputText = '' ;
@@ -59,14 +62,14 @@ export class BnaFilePanelComponent implements OnChanges {
59
62
if ( ! filePanelState . show ) {
60
63
cleanup ( ) ;
61
64
} else {
62
- this . block = filePanelState . block
65
+ this . block = filePanelState . block ;
63
66
const updatePosition = async ( ) => {
64
67
const result = await computePosition (
65
68
getVirtualElement ( filePanelState . referencePos ) ,
66
69
this . elRef . nativeElement ,
67
70
{
68
- placement : 'bottom-start ' ,
69
- middleware : [ flip ( ) ] ,
71
+ placement : 'bottom' ,
72
+ middleware : [ offset ( 10 ) , flip ( ) ] ,
70
73
}
71
74
) ;
72
75
this . renderer2 . setStyle (
@@ -100,44 +103,39 @@ export class BnaFilePanelComponent implements OnChanges {
100
103
}
101
104
}
102
105
103
- async onFileInput ( event : Event ) {
104
- const editor = this . editor ( )
105
- if ( ! editor . uploadFile || ! this . block ) {
106
+ async onFileInputChanged ( event : Event ) {
107
+ const editor = this . editor ( ) ;
108
+ if ( ! editor . uploadFile || ! this . block ) {
106
109
console . error ( 'uploadFile was not provided in editor options' ) ;
107
- return
110
+ return ;
108
111
}
109
112
110
- const files = ( event . target as HTMLInputElement ) . files
111
- if ( ! files ) return
112
-
113
- const file = files [ 0 ]
114
- const fileUrl = await editor . uploadFile ( file )
113
+ const files = ( event . target as HTMLInputElement ) . files ;
114
+ if ( ! files ) return ;
115
115
116
- editor . updateBlock (
117
- this . block ,
118
- {
119
- props : {
120
- url : fileUrl ,
121
- } ,
122
- }
123
- )
116
+ const file = files [ 0 ] ;
117
+ const fileUrl = await editor . uploadFile ( file ) ;
124
118
125
- editor . filePanel ?. closeMenu ( )
119
+ this . updateBlockWithEmbedFileUrl ( this . block , editor , fileUrl ) ;
126
120
}
127
121
128
- insertEmbed ( ) {
129
- const editor = this . editor ( )
130
- if ( ! this . block ) return ;
122
+ insertEmbedFile ( embedFileUrl : string ) {
123
+ const editor = this . editor ( ) ;
124
+ if ( ! this . block ) return ;
125
+ this . updateBlockWithEmbedFileUrl ( this . block , editor , embedFileUrl ) ;
126
+ }
131
127
132
- editor . updateBlock (
133
- this . block ,
134
- {
135
- props : {
136
- url : this . embedInputText ,
137
- } ,
138
- }
139
- )
128
+ private updateBlockWithEmbedFileUrl (
129
+ block : BlockFromConfig < FileBlockConfig , any , any > ,
130
+ editor : BlockNoteEditor < any , any , any > ,
131
+ embedFileUrl : string | Record < string , any >
132
+ ) {
133
+ editor . updateBlock ( block , {
134
+ props : {
135
+ url : embedFileUrl ,
136
+ } ,
137
+ } ) ;
140
138
141
- editor . filePanel ?. closeMenu ( )
139
+ editor . filePanel ?. closeMenu ( ) ;
142
140
}
143
141
}
0 commit comments