Skip to content

Commit 5bbfc71

Browse files
committed
feat: added test drag menu dropdown
1 parent 0fd4c47 commit 5bbfc71

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

src/ui/components/bna-formatting-toolbar/bna-formatting-toolbar.directive.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export class BnaFormattingToolbarDirective implements OnChanges {
2727
this.renderer2.addClass(this.elRef.nativeElement, 'Test');
2828
if (this.editor()) {
2929
this.editor().formattingToolbar.onUpdate((formattingToolbar) => {
30-
console.log(formattingToolbar);
3130
if (formattingToolbar.show) {
3231
this.renderer2.setStyle(this.elRef.nativeElement, 'display', 'block');
3332
this.renderer2.setStyle(

src/ui/components/bna-side-menu/bna-side-menu.directive.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class BnaSideMenuDirective {
1717
const editorSnapshot = this.editor();
1818
this.renderer2.setStyle(this.elRef.nativeElement, 'display', 'none');
1919
this.renderer2.setStyle(this.elRef.nativeElement, 'position', 'absolute');
20+
this.renderer2.setStyle(this.elRef.nativeElement, 'z-index', '1000');
2021
editorSnapshot.sideMenu.onUpdate((sideMenuState) => {
2122
if (sideMenuState.show) {
2223
this.renderer2.setStyle(this.elRef.nativeElement, 'display', 'block');

src/ui/components/bna-side-menu/default-buttons/drag-handle-menu/bna-drag-handle-menu.component.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,16 @@
99
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-4">
1010
<path stroke-linecap="round" stroke-linejoin="round" d="M6.75 12a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0ZM12.75 12a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0ZM18.75 12a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0Z" />
1111
</svg>
12-
1312
</button>
13+
<div class="hidden">asd</div>
14+
15+
<div id="dropdown" class="z-10 bg-white divide-y divide-gray-100 rounded-lg shadow w-44 dark:bg-gray-700" [ngClass]="{'hidden': !dragMenuShown}">
16+
<ul class="py-2 text-sm text-gray-700 dark:text-gray-200" aria-labelledby="dropdownDefaultButton">
17+
<li>
18+
<button (click)="deleteBlock()" type="button" class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Delete</button>
19+
</li>
20+
<li>
21+
<a href="#" class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Settings</a>
22+
</li>
23+
</ul>
24+
</div>

src/ui/components/bna-side-menu/default-buttons/drag-handle-menu/bna-drag-handle-menu.component.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CommonModule } from '@angular/common';
2-
import { Component, input } from '@angular/core';
3-
import { BlockNoteEditor } from '@blocknote/core';
2+
import { Component, input, OnChanges } from '@angular/core';
3+
import { Block, BlockNoteEditor } from '@blocknote/core';
44

55
@Component({
66
selector: 'bna-drag-handle-menu-btn',
@@ -9,11 +9,18 @@ import { BlockNoteEditor } from '@blocknote/core';
99
templateUrl: './bna-drag-handle-menu.component.html',
1010
styleUrl: './bna-drag-handle-menu.component.css',
1111
})
12-
export class BnaDragHandleMenuComponent {
12+
export class BnaDragHandleMenuComponent implements OnChanges {
1313
editor = input.required<BlockNoteEditor>();
14+
dragMenuShown = false;
15+
focusedBlock?: Block;
1416

1517
openDragMenu() {
1618
console.log('Open drag menu');
19+
this.dragMenuShown = !this.dragMenuShown;
20+
// this.editor().block;
21+
if (this.dragMenuShown) {
22+
this.editor().sideMenu.freezeMenu();
23+
}
1724
// this.editor().removeBlocks([this.editor.name]);
1825
}
1926

@@ -27,4 +34,25 @@ export class BnaDragHandleMenuComponent {
2734

2835
this.editor().sideMenu.blockDragEnd();
2936
}
37+
38+
ngOnChanges() {
39+
this.editor().sideMenu.onUpdate((state) => {
40+
if (!state.show) {
41+
this.dragMenuShown = false;
42+
this.focusedBlock = undefined;
43+
} else {
44+
this.focusedBlock = state.block;
45+
}
46+
});
47+
}
48+
49+
deleteBlock() {
50+
if (this.focusedBlock) {
51+
console.log('delete block', [this.focusedBlock?.id]);
52+
this.editor().removeBlocks([this.focusedBlock.id]);
53+
this.focusedBlock = undefined;
54+
this.dragMenuShown = false;
55+
}
56+
this.editor().sideMenu.unfreezeMenu();
57+
}
3058
}

0 commit comments

Comments
 (0)