Skip to content

Commit d59eed3

Browse files
committed
feat: add toolbar directive
1 parent 838ae87 commit d59eed3

File tree

4 files changed

+71
-5
lines changed

4 files changed

+71
-5
lines changed

src/ui/block-note-editor/_component/bna-editor.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
<bna-add-block-btn [editor]="editor" />
44
<bna-drag-handle-menu-btn [editor]="editor" />
55
</bna-side-menu>
6-
6+
<bna-formatting-toolbar [editor]="editor">
7+
<button type="button" (click)="editor.toggleStyles( { bold: true })">B</button>
8+
</bna-formatting-toolbar>
79
<bna-view [editor]="editor" class="block margin-icons" />
810
<bna-suggestions-menu
911
[editor]="editor"

src/ui/block-note-editor/_component/bna-editor.component.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ import {
2525
PartialBlock
2626
} from '@blocknote/core';
2727
import { DefaultSuggestionItem } from '@blocknote/core';
28+
import {
29+
BnaFormattingToolbarDirective
30+
} from '../../components/bna-formatting-toolbar/bna-formatting-toolbar.directive';
2831
import { BnaViewDirective } from '../../components/bna-view/bna-view.directive';
29-
import { BnaSideMenuDirective } from '../../components/side-menu/bna-side-menu.directive';
32+
import { BnaSideMenuDirective } from '../../components/bna-side-menu/bna-side-menu.directive';
3033
import {
3134
BnaAddBlockButtonComponent
32-
} from '../../components/side-menu/default-buttons/add-block-button/bna-add-block-button.component';
35+
} from '../../components/bna-side-menu/default-buttons/add-block-button/bna-add-block-button.component';
3336
import {
3437
BnaDragHandleMenuComponent
35-
} from '../../components/side-menu/default-buttons/drag-handle-menu/bna-drag-handle-menu.component';
38+
} from '../../components/bna-side-menu/default-buttons/drag-handle-menu/bna-drag-handle-menu.component';
3639
import {
3740
BnaSuggestionsMenuDirective
3841
} from '../../components/bna-suggestions-menu/bna-suggestions-menu.directive';
@@ -44,7 +47,8 @@ import {
4447
BnaSideMenuDirective,
4548
BnaAddBlockButtonComponent,
4649
BnaDragHandleMenuComponent,
47-
BnaSuggestionsMenuDirective
50+
BnaSuggestionsMenuDirective,
51+
BnaFormattingToolbarDirective
4852
],
4953
// eslint-disable-next-line @angular-eslint/component-selector
5054
selector: 'bna-editor',
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { BnaFormattingToolbarDirective } from './bna-formatting-toolbar.directive';
2+
3+
describe('BnaFormattingToolbarDirective', () => {
4+
it('should create an instance', () => {
5+
const directive = new BnaFormattingToolbarDirective();
6+
expect(directive).toBeTruthy();
7+
});
8+
});
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { Directive, effect, ElementRef, input, OnChanges, Renderer2, SimpleChanges } from '@angular/core';
2+
import { BlockNoteEditor } from '@blocknote/core';
3+
4+
@Directive({
5+
selector: 'bna-formatting-toolbar[editor]',
6+
standalone: true,
7+
})
8+
export class BnaFormattingToolbarDirective implements OnChanges{
9+
editor = input.required<BlockNoteEditor>();
10+
11+
12+
constructor(
13+
protected elRef: ElementRef<HTMLElement>,
14+
private renderer2: Renderer2
15+
) {
16+
17+
18+
}
19+
20+
ngOnChanges() {
21+
const position = this.elRef.nativeElement.getBoundingClientRect();
22+
this.renderer2.setStyle(this.elRef.nativeElement, 'display', 'none');
23+
this.renderer2.setStyle(this.elRef.nativeElement, 'position', 'absolute');
24+
this.renderer2.setStyle(this.elRef.nativeElement, 'z-index', '10000');
25+
this.renderer2.addClass(this.elRef.nativeElement, 'Test');
26+
if(this.editor()){
27+
this.editor().formattingToolbar.onUpdate( (formattingToolbar) => {
28+
console.log(formattingToolbar);
29+
if (formattingToolbar.show) {
30+
this.renderer2.setStyle(this.elRef.nativeElement, 'display', 'block');
31+
this.renderer2.setStyle(
32+
this.elRef.nativeElement,
33+
'top',
34+
`${
35+
formattingToolbar.referencePos.top -
36+
position.top +
37+
formattingToolbar.referencePos.height
38+
}px`
39+
);
40+
this.renderer2.setStyle(
41+
this.elRef.nativeElement,
42+
'left',
43+
`${formattingToolbar.referencePos.left - position.left}px`
44+
);
45+
} else {
46+
this.renderer2.setStyle(this.elRef.nativeElement, 'display', 'none');
47+
}
48+
});
49+
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)